Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : while loop - 2Next Topic : do while loop - 2

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: Which one is odd among these?
1)while
2)do while
3)for
a)  1
b)  2
c)  3
d)  None ofthese
Correct Answer : b
Explanation : The do-while loop is odd loop, because it a down checker loop. for and while loops are top checker loop.


Q2: What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {   do
            printf("Apna Time");
        while (0);
            printf(" Ayega");
    }
a)  Apna Time
b)  Ayega
c)  Apna TimeAyega
d)  Apna Time Ayega
Correct Answer : d
Explanation : The do part is executed first, and then while(0); means condition is false, so control comes out from the loop. From loop Apna Time is printed and out side loop Ayega is Printed. So output will be Apna Time Ayega.


Q3: What will be result of compiling and executing the below given c code?
#include <stdio.h>
int main()
{   int con=15,ind=30;
    do 
	{ ind/=con;
    } while(con--);  
    printf ("%d",ind);
    return 0;
}
a)  will print 0
b)  will print -1
c)  runtime error
d)  syntax error
Correct Answer : c
Explanation : Due to continuous decrements when con becomes 0, the ind is divided 0, and in c if an integer is divide by 0, then its a runtime error.
Learn c in hindi here


Q4: What will be result of compiling and executing the below given c code?
#include <stdio.h>
int main()
{   int con=15,ind=30;
    do 
	{ ind/=con;
         con--;
    } while(con);  
    printf ("%d",ind);
    return 0;
}
a)  0
b)  -1
c)  Syntax Error
d)  Runtime Error
Correct Answer : a
Explanation : In first iteration, ind becomes,2 , in second iteration ind becomes 0, after that con is continuously dividing ind, and con is also decremented. When con become 0, the loop is terminated and value of ind become 0.
Learn c in hindi here


Previous Topic : while loop - 2Next Topic : do while loop - 2