in Programming in C
1,144 views
1 vote
1 vote
  int main (){      int a=5,b=3;      printf("%d", a+++++b); // 5 +'s  }

Please Explain.

in Programming in C
1.1k 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

3 Comments

That i also know even a+++ ++b will give same result but a+++++b not

the reason i want to know!
0
0
simply to say its not a valid lexical unit. note: lexical unit always tries to find longest valid lexical unit. after lexical analyzer sees + after a , it identifies a as identifier (variable) , and try to identify next token ++++++b it is not valid token. as space is separator , if you give space a++ + ++b , it identifies a as variable and ++ as operator and + as operator and b as identifier.
0
0
0
0
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