Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

C | Operators | Question 23

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Predict the output of following program? 


#include <stdio.h>
int main() {
    int x = 10;
    int y = 20;
    x += (y += 10);
    printf("%d %d", x, y);
    return 0;


40 20


40 30


30 30


30 40

Answer: (B)


The main statement in question is “x += y += 10”. Since there are two += operators in the statement, associativity comes into the picture. Associativity of compound assignment operators is right to left, so the expression is evaluated as x += (y += 10).

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads