pre increment operator Output

#include
int main()
{ int v;
scanf("%d",&v);;
printf("%d\n",(++v*++v+(++(++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
//