• retagged by
2,227 views
2 2 votes

what is the o/p
 

#include<stdio.h>
void main()
    {
    int a=5;
    printf("%d   %d   %d",a++,++a,--a);
    }


also suggest me notes so i can clear my concept about printf function (For Gate)

6 Answers

Best answer
1 1 vote

According to C standard, the answer is undefined as "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored."   

To know more read this explanation : https://www.quora.com/What-does-an-expression-involving-multiple-post-pre-decrement-increment-operators-evaluate-to-in-C-and-C++

• selected by
0 0 votes
The result is dependent on the compiler as wether the expression should be evaluated from left-to-right or right-to- left is not defined anywhere . Different compiler use to evaluate the given expression in different way.

 

This is an ambiguous question and will not be asked in GATE for sure.
–1 –1 vote
In your question there are following operator are used..
Post increment operator:-.  eg...a++ (aplusplus)that means it first use the value then after increase it by 1and use it..so a=5
So,*******""first output is 5
Pre increment operator:- eg.++a (plusplus a) that means it first increase the value by 1 and after then use..above a store the value 6 then
So,******""second output is 7
Pre decrement operator:- eg.--a(minus minus a) that means it first decrease the value by 1 and after then use.above a store 7
Then
So,******""Third output is 6
• edited by
Position:
Show:

Related questions

3 3 votes
1 answers 1 answer
840
840 views
junaid ahmad asked Oct 31, 2017
840 views
OUTPUT OF THE FOLLOWING PROGRAMME#include<stdio.h int main() { int n1=10; int n2=15; int n3; n3=~n1; printf("%d",n3); return 0; }Basically here i want to understand how d...
4 4 votes
3 answers 3 answers
1.2k
1.2k views
suvasish pal asked Aug 26, 2017
1,218 views
Will it result in to an error if a header file is included twice?[A].Yes[B].No[C].It is compiler dependent
1 1 vote
1 1 answer
1.6k
1.6k views
Vasu Srivastava asked Aug 18, 2017
1,567 views
#include <stdio.h int main(void){ int i=511; char *p = (char *)&i; printf("%d", *p); }OK so why take 2's complement and not simple binary number? Means, why is C giving -...
2 2 votes
1 1 answer
787
787 views
Sugumaran asked Feb 7, 2018
787 views
#include<stdio.h int main() { int x=191; char *p; p=(char*)&x; printf("%d",*p); }explain it