I have a simple question. Can a pointer be incremented in a for loop? In my program, I use a pointer variable and use it in a for loop like such:
for(*var1 = 1; *var1<100 ;*var1++)
int function(int* var1)
{
if(*var1 blah blah)
{do blah blah}
if(blah)
{blah}
}
}
The variable is not incremented by the ++ even when the if conditions are not met and the loop shouldn't break. the *var1 stays at 1. Any help would be appreciated. Thank you!
*p++ means *(p++). That is, p gets incremented and the expression evaluates to what p pointed to previously. If you want to increment what p points to, you need (*p)++. Alternatively, you can use ++*p.