postfix and prefix in printf and for function (C) -
this question has answer here:
- what difference between ++i , i++? 17 answers
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
Post a Comment