help regarding regarding ++a or a ++ etc

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <conio.h>

int main()
{
	int a = 10, b= 10, c, d, e;
	
	c= ++a + b++;
	d= c++ + a++;
	e= (--a + b--) / ++c - d--;
	printf("%d", c); \\ 23
	printf("\n%d", d); \\31
	printf("\n%d\t%d\t%d\t%d%\t%d", a, b, c, d, e); \\ 11 10 23 31 -32
	getch(); 
}

good day! i might ask when i run this code these are the answers. Im trying to do some exercises,and i still can't figure this out

++a = +1 (a) = 11
b++ = use the current value before adding 1 = 10

my answer is 21 but why 23, please help me, clear this up.
You forget that you are incrementing the c variable twice in the rows that follows.
please explain it to me thank you, we are just starting regarding this lesson and i can't understand it properly. because of our lecturer who thinks that we should know this in one go,
Last edited on
What I meant was that you are correct that the value of c is 21 after line 8, but c is also changed on line 9 and 10 and that's why it has a different value when it reaches the print statement on line 11.
Last edited on
thank you!
Topic archived. No new replies allowed.