while(a[++i])
printf("%d",*++a - 'a');
Here first the while condition executes i.e a[++i] --> *(a + ++i) --> So here ++ has high precedence than binary '+'. So first i increments which then is added to address pointed by char pointer a and then finally dereferenced.
Now in the printf statement " *++a - 'a' " --> ++ has high precedence then '*' - dereference and then finally binary '-' will execute.
Value of i |
a[i++] --> while loop condition |
*++a , i value |
*++a - 'a' , a points to |
0 |
a[1] = 'b' |
b , i = 1 |
1 [as 98 - 97 ] , a points 'b' |
1 |
a[2] = 'd' |
c , i = 2 |
2 [as 99 - 97] , a points 'c' |
2 |
a[3] = '\0' --> breaks while loop |
|
|
Hence the code outputs 12.