Posts: 220
Threads: 54
Joined: Jan 2014
Good morning.
The sizeof() changes what?
For example, between the two codes that I will present to you:
pawn Код:
for (new i = 1; i <= totalcars; i++)
And:
pawn Код:
for (new i = 1; i <= sizeof(totalcars); i++)
Thx !!
Posts: 220
Threads: 54
Joined: Jan 2014
I have:
new totalcars = 0;
Therefore the use of sizeof is good in this case?
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
It depends.
For example, if you want to loop through all the indexes of an array, using sizeof will be correct (not that it shouldn't be "<= sizeof (...);" because that will cause run time error 4. You'll need to use either "<" or "!=". Also indexes on arrays start always from 0 and not 1.
If you have an array (such as for houses - an example) and you want to loop only through the houses that exist, then if you store in a global variable how many houses there are, you can loop using the first one (without the '=' sign as I mentioned above).