What is the output of the following C program? main() { int a=10; int b; b=a++ + 20; printf("a=%d b=%d",a,b); }

  1. a=11 b=31

  2. a=10 b=30

  3. a=11 b=30

  4. None of the Above


Correct Option: C

AI Explanation

To determine the output of the given C program, let's go through the code step by step:

  1. Initialize the variable a with a value of 10.
  2. Declare the variable b.
  3. Assign the value of a (10) to b and then increment the value of a by 1 using the post-increment operator (a++).
    • After this step, a becomes 11 and b becomes 10.
  4. Print the values of a and b using printf() function with the format string "a=%d b=%d".
    • The values of a and b are 11 and 10 respectively.

Therefore, the correct answer is:

C. a=11 b=30

Find more quizzes: