What is the different?
#1

Hi

I would like to know what is the different between
Код:
for(new i = 0; i < MAX_*****; i++)
{
    *******
}
and
Код:
for(new i = 0; i < sizeof(*****); i++)
{
    *******
}
??
Reply
#2

new someVar[2][10];
printf("%d %d", sizeof (someVar), sizeof (someVar[]));
it will print 2 and 10. someVar[2][10] 2 and 10 you got it?
Reply
#3

Sizeof is used when arrays are involved. Plain constants in other cases (e.g. a MAX_PLAYER loop). I don't know how to explain this any better. It is generally more favorable to use the sizeof operator whenever arrays are involved since then the size will always be correct.
Reply
#4

So this one
Код:
for(new i = 0; i < sizeof(*****); i++)
{
    *******
}
is better than the other one?
Reply
#5

Quote:
Originally Posted by BrianS123
Посмотреть сообщение
So this one
Код:
for(new i = 0; i < sizeof(*****); i++)
{
    *******
}
is better than the other one?
It depends if arrays are involved.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)