• Post Reply Bookmark Topic Watch Topic
  • New Topic

postfix, prefix and arithmetic operator precedence query  RSS feed

 
Vijay Kumar Raman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output : 8

x++ + x++ * --x
2 + x++ * --x
2 + 3 * --x
2 + 3 * 2
2 + 6
result: 8
Is this correct ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. x++ is a post-increment operation. It returns the old value of x, not the new one:
 
Vijay Kumar Raman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephan,
Thanks for the answer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!