Question discussion

What will be the output of the given C program?

359250Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the given C program?
#include <stdio.h>
int main()
{
{
    int x = 10, y = 20;
    {
    {
        int y = 40;
        x++;
        y++;
    }
        printf("x = %d, y = %d\n", x, y);
    }
}
    return 0;
}
  • Ax = 11, y = 41
  • Bx = 10, y = 41
  • Cx = 10, y = 20
  • Dx = 11, y = 20
Correct answer: D

Explanation

The inner y = 40 is a separate variable and does not affect the outer y = 20. x is incremented once, so the output is x = 11, y = 20.

Discussion 0

Nobody has replied yet. Start the discussion!