Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : do while loop - 1Next Topic : break and continue - 1

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “ do while loop statement”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. It will improve their understanding of C Language. Here is a listing of C questions and puzzles on “do while loop statement” along with answers and/or explanations.

Q1: What will be the output of following c code?
#include<stdio.h>
int main()
{     int xy=1;
       do
       {     printf("%d ",xy);
       }while(xy++<=3);
       return 0;
}
a)  1 2 3
b)  1 2 3 4 5
c)  1 2 3 4
d)  None of these
Correct Answer : c
Explanation : The initial value of xy is 1, so 1 is printed, then condition is tested for 1, and then xy is incremented by 1, thus next time 2 is printed, then condition is tested for 2 and then incremented by 1, and next time 3 is printed, and then condition is tested for 3, and value is incremented by 1, so 4 is printed. Now condition is tested for 4, and become false, so loop is terminated here.


Previous Topic : do while loop - 1Next Topic : break and continue - 1