Let us C
closed

closed by
464 views
0 votes
0 votes
closed with the note: Undefined behaviour; not relevant for GATE
#include<stdio.h>
int main()
{
    int x=20;
    printf("%d %d ",x--,++x);
}

unable to understand how it prints the output. plz help
closed by

1 Answer

0 votes
0 votes
yes the above que's output will be compiler dependent but if we ignore the compiler issue it will be solve.

when we are working with printf statement  and it contain multipal argument then it always execute from left to right because it work with the help of stack. In printf statement data need to be pass toward right to left & data need to be print toward from left to right.(LIFO).

initial the value x =20, first execute right to left  ++x is preincrement it gives 21 and push into stack. now new value of x=21,

 now x-- post decrement which push old value of x 21 push into stack then decrement the value of x=20(new value of x);

TOS cantain 21, pop all we get 21,21.as output and value of x is 20

Related questions

3 votes
3 votes
1 answer
1
Rudra Pratap asked Jun 25, 2017
1,273 views
#include<stdio.h int main() { int i = 0x1 << sizeof(int)*8-1; printf("\n%x",i); i = i > sizeof(int)*8-1; printf("%d",i); }Find the output ?
0 votes
0 votes
1 answer
2
Pragya asked Mar 29, 2017
1,116 views
I am unable to understand the error code. What does 'invalid conversion from int to int mean ? plz help.The code-#include <stdio.h>int function(int *);int main(){ int ...
0 votes
0 votes
1 answer
3
ranarajesh495 asked Oct 9, 2018
571 views
If we are taking character as input then how we can check the character against a a range of numbers. Please explain
1 votes
1 votes
0 answers
4
KashishNarang asked Aug 23, 2018
250 views
Output will be-int main(){ int a =0,b=1,c=3:*((a)?&b&:&a)=a ? b : c;printf("%d %d%d ", a,b,c);}