Ok, the first thing you have to know is, a char is stored in the memory as Ascii Table. So in the memory the char c
will have a integer value of '8'. From the table we know that the integer value of '8' is 56. According to the table we'll get:
'8': 56
'0': 48
'9': 57
So let's get started.
c++
: It is a statement which adds c by one and return the value of current c.
Example:
int a,c;
c=1;
a=c++;
printf("a=%d,c=%d",a,c);
The result of this code is "a=1,c=2"
so %d
of c++ is still 56.
d+=c>'0'&&c<='9'
: According to C's priority this statement will be like:
d+=(c>'0'&&c<='9')
So let's start with c>'0'&&c<='9'
first. It is a condition statement. Is c's Ascii value great or equal to 0's Ascii value AND less or equal to 9's Ascii value?( Notice c's Ascii is 56 or 57 now because the evaluation order of printf
is undefined. So it will be 56 if this statement is evaluated before c++
or 57 if after c++
. But both way, c<='9'
is true ) YES. So the statement is true. In C the TRUE is 1.
So d+=c>'0'&&c<='9'
will be d+=1
which means d=d+1. So %d
of d is 9.
So the result is "9 9 56"