postfix and prefix in printf and for function (C) -


this question has answer here:

i'm sorry, i'm still noob @ c. wonder why post , prefix have different effect in "printf" have same effect in "for"or maybe in other loop ?

example :

#include <stdio.h> main() {     int number = 0;     printf("%d.\n", ++number); //it prints 1     return 0; }   ...............     printf("%d.\n", number++); //it prints 0 ............... 

but in "for"

#include<stdio.h> main() {     int number;     (number = 0; number < 5; ++number);     {         printf("%d\n", number); //it prints 0,1,2,3,4     }     return 0; } .............     (number = 0; number < 5, number++);     {        printf("%d\n", number); //it prints 0,1,2,3,4     } ......................... 

in for, result of third expression thrown away, doesn't matter if number or number+1. side effect of changing value of number variable remains, , same post- , pre-increment.

but when pass function argument, value of expression matters, , different. note for not function, btw!


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -