pre increment operator Output

int main()
{ int v;
return 0;

when I execute the above lines say v=3 i get output 37,now I can’t understand how this is evaluated?

Read this first.

Let’s substitute v with n as I like the latter (no pun intended) more. Your kind of magic expression can be calculated as: (n + 1) * (n + 2) + (n + 4). Just substitute step by step from left to right.

  1. ++n*++n+(++(++n))
  2. (n+1)*++n+(++(++n))
  3. (n+1)*(n+2)+(++(++n))
  4. (n+1)*(n+2)+(++(n+3))
  5. (n+1)*(n+2)+(n+4)
1 Like