C program

Joined
Mar 3, 2021
Messages
240
Reaction score
30
First, we evaluate the right side. Pre-increment and post-increment have the highest priority there and are the same priority, so we go left to right. Let's put some parenthesis around those to make it a bit easier to read and then evaluate them. After the two increments, p will be 12.

Code:
p += ++p + p++
p += (++p) + (p++)
p += (11) + (12)
p += 23
p = 12 + 23
p = 35

To verify, you can simply compile and run it.
C:
#include <stdio.h>

int main(){
        int p = 10;
        p += ++p + p++;
        printf("%d\n", p); // 35
        return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top