Computer Science, asked by fazeelkhalid9, 1 year ago

what is the output of following c program

#include
int main() {
int x=1;
printf("%d %d %d", x, x++, ++x);
return 0;

}
and reason in detail

Answers

Answered by neelrambhia03
0

Answer:

1 2 2

Explanation:

x=1

X++ = x+1 = 1+1 = 2

++X = 1+x = 1+1 = 2


fazeelkhalid9: are you programmer
fazeelkhalid9: if yes then read my code again again again again...........
fazeelkhalid9: can you tell me what is the purpose of x++ and ++x
neelrambhia03: Not really a programmer
neelrambhia03: I have studied C
neelrambhia03: when you put increment operator after any variable(s), increment is done later and if you put before variable(s) increment is done first.
neelrambhia03: Eg. if x = 3 and y is 2 then x-y++ is equal to 2
neelrambhia03: ++x-y is equal to 2
neelrambhia03: However 1 gets added to x-y in first case and 1 gets added to x in the second case.
Similar questions