Let us C
closed

• closed by
1,323 views
0 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

1 Answer

0 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
Position:
Show:

Related questions

4 4 votes
1 1 answer
2.1k
2.1k views
Rudra Pratap asked Jun 25, 2017
2,087 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 0 votes
1 1 answer
1.6k
1.6k views
Pragya asked Mar 29, 2017
1,640 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 0 votes
1 1 answer
1.0k
1.0k views
ranarajesh495 asked Oct 9, 2018
1,031 views
If we are taking character as input then how we can check the character against a a range of numbers. Please explain
1 1 vote
0 0 answers
645
645 views
KashishNarang asked Aug 23, 2018
645 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);}