1,154 views

2 Answers

0 votes
0 votes

 https://stackoverflow.com/questions/5341202/why-doesnt-ab-work-in-c 

printf("%d",a+++++b); is interpreted as (a++)++ + b according to the Maximal Munch Rule!.

++ (postfix) doesn't evaluate to an lvalue but it requires its operand to be an lvalue.

! 6.4/4 says the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token"

- Prasoon Saurav

0 votes
0 votes

see this code :

  #include<stdio.h>  int main (){      int a=5,b=3;      printf("%d", a++++); // 5 +'s  }

Now here see the analysis first we have a++ ,no issue we got a=5 ,now what I did is 5++ which is blunder since post-increment returns rvalue and for any further operation I need lvalue for it ,therefore it is an error  post-increment .

Also you can see that when we write a++ it is evaluated as a=a+1 ,but when we write 5++ it makes no sense since it would be 5=5+1 ,which is invalid ,hence lvalue required

please refer to this link once .

http://stackoverflow.com/questions/17440117/confused-with-pre-and-post-increment-operator 

Related questions

1 votes
1 votes
3 answers
1
ajit asked Oct 1, 2015
1,610 views
what is the output of the following c code?#include<stdio.h void main() { int index; for(index=1;index<=5;index++) { printf("%d",index); if(index==3) continue; } }a)1245b...
2 votes
2 votes
5 answers
2
debanjan sarkar asked Sep 3, 2015
6,457 views
void myfunc(int X){ if(X 0) myfunc( X ); printf("%d", X); } int main(){ myfunc(5); return 0; }0,0,1,2,3,44,3,2,1,04,3,2,1,0,00,1,2,3,4
1 votes
1 votes
1 answer
3
Nishikant kumar asked Nov 16, 2015
936 views
void abc(int x, int y){ pf("%d%d", x, y); } void main(){ int a; a = 12; abc(++a, a++); pf("%d", a); }14,12,1413,12,1311,12,1214,14,14
0 votes
0 votes
1 answer
4
debanjan sarkar asked Aug 21, 2015
1,125 views
Find the output of the following c code- main() { char *ptr="gatebuddy"; *(ptr)++; ptr++; printf("%s\n",ptr); }