edited by
548 views
1 votes
1 votes
int main()
{
   int x=5,*p;
   p=&x;
   *p=x++ + *p;
   printf ("%d %d",x,*p);
}
We have this program
now
here *p= 5++ + (*p) -> *p= 5 + 5 =10   
so x location is 10
and then the postfix x++= 10+1=11
so output is 11 11

int main()
{
   int x=5,*p;
   p=&x;
   *p=x++ + 5;
   printf ("%d %d",x,*p);
}
Now in the same question we add a constant 5 , Here x is not incrementing later .
*p= x++ + 5;
*p= 5+5=10
output 10 10  , when x is not taking the postfix increment ???
edited by

1 Answer

0 votes
0 votes

Hii @Rajib,

Postfix increment/decrement has higher precedence than unary operators.

source : https://stackoverflow.com/questions/24579014/does-postfix-operator-really-has-a-higher-precedence-than-prefix

So in your 1st Program first x++ executed and then  *p which takes incremented value(6)

so *p=(x++) + *p ==> 5+6 ==> 11.

in second program simple addition happens

*p=(x++)+5 ==>5+5 ==>10;

 

Related questions

1 votes
1 votes
0 answers
2
Akshay Nair asked Jan 29, 2018
445 views
What is the output of the following program?void main(){printf("%d",5%2);printf("%d",-5%2);printf("%d",5%-2);printf("%d",-5%-2);printf("%d",2%5);}A) 1,-1 -1 1 0B)1 -1 1 -...
1 votes
1 votes
1 answer
3
2 votes
2 votes
2 answers
4
Khushal Kumar asked Jul 4, 2017
733 views
output of the following program is 'no' but why. #include <stdio.h>int main(){ if (sizeof(int) -1) printf("Yes"); else printf("No"); return 0;}