Please Turn On Java Script To Access This Site.

C Institute | Questions


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

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “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 “while loop statement” along with answers and/or explanations.

Q1: What will be the output of the C program?
#include<stdio.h>
int main()
{	int i=0;
         i++;
	 while(i++)
	{       printf("%d ", i);
		if(i == 6) 
		break;
                ++i;
	}
	return 0;
}
a)  1 3 5 6 9
b)  2 4
c)  2 4 6
d)  Infinite loop
Correct Answer : c
Explanation : The value of i is incremented twice before entering into loop body. So in first pass i will be 2, then 4 and then 6. After printing 6 the condition of if is true, so the break will be executed and loop is terminated due to break.


Q2: How many times Zomato will be printed?
#include<stdio.h>
int main()
{	int a=10;
	while(a < 10, -1)
	{	printf("Zomato ");
		a++;
	}
	return 0;
}
a)  Zero times
b)  One times
c)  Ten Times
d)  Infinite Times
Correct Answer : d
Explanation : Here Comma is a operator, so the second expression after comma is used as condition of loop. -1 is a non zero value, so loop will run infinite times.


Q3: What will be the output of the C program?
#include<stdio.h>
int main()
{	int mn=0;
	while(mn++)
	{	printf("%d ",mn);
		if(mn==5)
			break;
	}
        return 0;
}
a)  1 2 3 4 5
b)  0 1 2 3 4 5
c)  0
d)  No output
Correct Answer : d
Explanation : while(mn++) means while(mn) and then mn=mn+1, the initial value of mn is 0. so while(0) means condition false in first iteration, therefore no output.
Learn c in hindi
Learn how post increment and decrement works


Q4: What will be the output of the C program?
#include<stdio.h>
int main()
{	int ab=7;
	while(ab==7--)
		printf("Jai Hind ");
	return 0;
}
a)  Jai Hind
b)  Jai Hind printed infinite times
c)  Jai Hind printed two times
d)  Syntax Error
Correct Answer : d
Explanation : It will produce syntax error, because Increment(++) and decrement(--) operators cannot be applied on constant.
Watch solution video here
Learn c in hindi


Q5: What will be the output of the C program?

#include<stdio.h>
int main()
{       
	char tv=(char)(1);
	while(tv==1)
	{  printf("Mast ");
	   break;
	}
	return 0;
}
a)  Mast printed once
b)  Mast printed infinite times
c)  No output
d)  None of these
Correct Answer : c
Explanation : The condition is true in first time so Mast is printed, after printing break terminates the loop.
Learnc here
Watch solution here


Q6: What will be the output of the C program?
#include<stdio.h>
int main()
{	int in=0;
	while(in+1)
		while(in<<2)
			while(in+4)
			{	printf("Banni Friend");
				if(in==3)
					break;
			}
		return 0;
}
a)  Banni Friend will be printed infinite times
b)  No output, but loop runs infinitely
c)  Syntax Error
d)  Banni Friend will be printed once
Correct Answer : b
Explanation : Watch solution here


Q7: What will be printed?
#include<stdio.h>
int main()
{	int ts=-1;
	do 
	{	while(ts++);
		while(ts)
			ts--;
		for(ts++;0;ts++);
		break;
	}while(1);
	printf("%d",ts);
	return 0;
}
a)  2
b)  0
c)  1
d)  3
Correct Answer : c
Explanation : Watch solution video here


Q8: What will be output?
#include<stdio.h>
int main()
{	int etc=-1;
	while(++etc==0)
		printf("PHP ");
	return 0;
}
a)  PHP printed infinite times
b)  PHP printed once
c)  PHP printed twice
d)  PHP printed 10 times
Correct Answer : b
Explanation : Watch Solution Video Here


Q9: What will be output?
#include<stdio.h>
int main()
{	int etc=-1;
	while(1+etc==0)
		printf("PHP ");
	return 0;
}
a)  PHP printed once
b)  PHP printed twice
c)  PHP printed ten times
d)  PHP printed infinite times
Correct Answer : d
Explanation : Watch Solution Video Here


Q10: What will be the result of compiling and executing the following program?
#include<stdio.h>
int main()
{	int bin=3,etc=-3;
	while(bin>etc==1)
		printf("PHP ",bin--,etc++);
	return 0;
}
a)  PHP printed twice
b)  PHP printed thrice
c)  PHP printed infinite times
d)  Syntax Error in printf
Correct Answer : b
Explanation : Find solution here


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