First, I know this is bad programming and most people say to not use it, but my teacher uses this stuff on his test a bunch.
Code:
#include <stdio.h>
#define max 52
main(){
int a=10,b,c,d,e,f,g;
printf("%d %d %d\n",a,a++,++a);
a=1;
b = ++a + ++a + ++a;
a=1;
c = ++a + ++a + --a;
a=1;
d = --a + ++a + ++a;
a=1;
e = ++a + --a + ++a;
f=max+max;
g=++max;
printf("%d\n",b);
printf("%d\n",c);
printf("%d\n",d);
printf("%d\n",e);
printf("%d\n",f);
printf("%d\n",g);
getchar();
/* This prints
12 11 11
10
8
4
4
104 */
}
Can someone explain step by step why b,c,d,e are what they are? If you can break it down to 1+1=2 (step by step at the lowest level) i would love it because I am lost when it comes to this.
I don't really understand incrementations added together.
And is my understanding of printf("%d %d %d\n",a,a++,++a);
correct. So with this since incrementations are right priority (so like reading right to left), the printf does ++a first and saves it as 11 then does a++ which saves it as 11 then increments by 1 then saves a which is 12 all in temp memory and then displays them?
And why can't you increment max when it is defined as 52?
Thank you for all your help
Zach