Languages [HCL Placement]: Sample Questions 13 - 13 of 13

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 13

Question

MCQ▾

Find the output for the following C program

  1. inti =10
  2. main()
  3. {inti =20,n;
  4.     for(n=0;n<=i;)
  5.     {inti=10;
  6.         i++;
  7.     }
  8.     printf("%d", i);
  9. }

Choices

Choice (4)

a.

20

b.

10

c.

12

d.

All of the above

Answer

a.

Explanation

  • Firstly, one integer i is defined with value 10. In the main () function one more time variable i is defined with 20 and variable n is declared. In for loop n is initialized with 0. In the condition value of n is compared with value of i.
  • If it is less than or equal to i then i will be initialized with 10 and gets incremented. After the complete execution of for loop, we want to print the value of i, which is in the main () function. Here, variable i is initialized with 20 so, 20 gets printed on the screen.

Developed by: