What will be the output printed by the following C program? void main() { int…

2021

What will be the output printed by the following C program?

void main()

{
int x = 1, i, y = 2;
for (i = 0; i < 5; i++)
{
x << 1;
y = x + i;
}
printf("%d, %d", x, y);
}

  1. A.

    1, 5

  2. B.

    32, 5

  3. C.

    1, 72

  4. D.

    32, 72

  5. E.

    Question not attempted

Attempted by 458 students.

Show answer & explanation

Correct answer: A

Step 1: The variable x is initialized to 1, and y is initialized to 2. Step 2: The for loop runs for i = 0 to 4 (5 iterations). Step 3: Inside the loop, x << 1 performs a left shift on x, but the result is not assigned back to x. Therefore, x remains 1 throughout the loop. Step 4: In each iteration, y is updated as y = x + i. Since x is always 1, y becomes 1 + i. Step 5: After the loop, the final values are x = 1 and y = 1 + 4 = 5. Step 6: The printf statement prints the values of x and y, so the output is "1, 5".

Explore the full course: Up Lt Grade Assistant Teacher 2025