Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

am confusing in operator precednce pls explain me

 
giribabu rosi
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1+2*3%4+5/4
 
Rohan Kayan
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1+2*3%4+5/4

= 1+((2*3)%4)+(5/4)
= 1+(6%4)+1
= 1+2+1
= 4

As the precedence of * / % are same they will calculate left to right , that's why 2*3 and 5/4 will be the first operation , then 6%4 and then the sum of all three.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic