in the following loop which i++ will be executed first?the one which is inside the for loop or the one at line no 3?
enter code here
1.for(i = 0; i < 3; i++) {
2.a[i] = a[i] + 1;
3.i++;
4.}
in the following loop which i++ will be executed first?the one which is inside the for loop or the one at line no 3?
enter code here
1.for(i = 0; i < 3; i++) {
2.a[i] = a[i] + 1;
3.i++;
4.}
The one inside the loop is executed first. The one in the loop declaration is always executed at the end of each loop before it starts its next iteration.
Is it difficult to test it yourself?:
#include <stdio.h>
int main(void) {
for(int i = 0; i < 50; i++)
{
printf("i before increment = %d\n", i);
i++;
printf("i after increment = %d\n", i);
}
return 0;
}
Run and test it yourself https://ideone.com/N76Q2n
and everything will be clear.