Code:#include<stdio.h> void main() { int i=-1,m; m=i++; printf("%d %d",i,m); }
Code:#include<stdio.h> void main() { int i=-1,m; m=i++; printf("%d %d",i,m); }
The output will be 0 and -1...
This is because of the m = i++ line... m is assigned the value of I (-1) and then I is incremented to 0.
FWIW... the correct form of main is... int main (void) ... and C programs always return a value to the operating system on exit...
Code:#include<stdio.h> int main (void) { int i=-1,m; m = i++; printf("%d %d",i,m); return 0; }
But he never put it that way did he? He asked whats the output. Perhaps he could have been much smarter in asking questions.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
I second this. I am assuming the poster is relatively new to programming, and the pre/post increment operator can lead to confusing problems if you don't understand the subtle difference between them.I see no problem with giving him an answer.