Please Turn On Java Script To Access This Site.

C Institute | Questions


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

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 following C code?

    #include <stdio.h>
    int main()
    {   while (true)
            printf("In loop ");
        printf("Outside loop");
    }
a)  In loop printed once
b)  In loop printed infinite times
c)  In loop Outside loop
d)  Syntax Error
Correct Answer : d
Explanation : true is not a keyword in c, so its syntax error.
Learn c from scratch


Q2: What will be the output of the C program?
#include<stdio.h>
int main()
{		int nm=0;
		while(nm<3,nm=0,nm<5)
		{	printf("BulBul");
			nm++;
		}
	return 0;
}
a)  BulBul printed 5 times
b)  BulBul printed 4 times
c)  BulBul printed infinite times
d)  Syntax Error
Correct Answer : c
Explanation : The while loop have a condition (i < 3, i = 0, i < 5) . The loop continues as infinite because i is initialized to 0 each time.
Learn C Here


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

#include<stdio.h>
int main()
{       while(!!NULL);
		printf("New India");
	return 0;
}
a)  New India printed once
b)  New India printed infinite times
c)  New India printed 2 times
d)  Syntax Error
Correct Answer : a
Explanation : New India printed once because the while(!!NULL); is terminated by the semicolon so the printf() is not controlled by while loop.


Q4: What will be the output of the C program?
#include<stdio.h>
int main(){
	int ab=-1;
	do 
	{     printf("Hi ");
	}while(ab++);
	return 0;
}
a)  Hi Hi
b)  Hi printed infinite times
c)  Syntax Error
d)  Runtime Error
Correct Answer : a


Q5: What will be the output of the C program?
#include<stdio.h>
int main()
{	while(!printf("C is awesome"));
	return 0;
}
a)  C is awesome
b)  C is awesome printed twice
c)  C is awesome printed infinite
d)  Syntax Error
Correct Answer : a


Q6: How many times Swiggy will be printed?
#include<stdio.h>
int main()
{	int a=10,b=13;
	while(++a < --b)
		printf("Swiggy");
	return 0;
}
a)  1 times
b)  2 times
c)  3 times
d)  Infinite Times
Correct Answer : a
Explanation : In the while loop condition first a is increased so a become 11, b is decreased so b become 12, now they are compared, here 11 is less than 12 so Swiggy is printed. In next iteration a further increased by 1, so a become 12, b is decreased by 1, so b become 11, here 12 is not less than 11, so condition of loop results in false, and loop is terminated.


Q7: What will be the output of the C program?
#include<stdio.h>
int main()
{	int ab=5;
	while(printf("%d", 5) == 1 == ab)
	{	printf(" Bingo ");
	}
	return 0;
}
a)  5 Bingo printed twice
b)  5 Bingo printed once
c)  5 printed once
d)  5 Bingo printed infinite times
Correct Answer : c
Explanation : In the condition of while loop, the printf()function is executed which prints 5 and returns 1. So condition becomes 1==1==ab. Here 1==1 yields 1, so expression becomes 1==ab, that yields 0. So only 5 is printed once.
Learn c in hindi
Watch the solution video


Q8: What will be the output of the C program?
#include<stdio.h>
int main()
{	int in=5,pk=3;
	while(in-pk)
		printf("%d %d ",in--,pk++);
	return 0;
}
a)  5 3 4 4 3 5
b)  5 3 4 4 3 5 2 6 prints continuously
c)  5 3
d)  Syntax Error
Correct Answer : c
Explanation : Watch solution here


Q9: What will be the output of the C program ?
#include<stdio.h>
int main()
{	float fiattt=10.5;
	while(fiattt)
	{       printf("Fiattt Running ");
		fiattt-=1.5;
		if(fiattt==9)
			break;
	}
	return 0;
}
a)  Fiattt Running printed Twice
b)  Fiattt Running printed Once
c)  Fiattt Running Printed Infinite Times
d)  Syntax Error
Correct Answer : b
Explanation : Watch solution video here


Q10: What will be the output of following c program?
#include<stdio.h>
int main()
{	float bin=420.2;
	while(bin==420.2)
	{       printf("Bin ");
			bin-=420.2;
	}
	return 0;
}
a)  Bin printed once
b)  loop will not run
c)  Bin printed infinite times
d)  Syntax Error
Correct Answer : b
Explanation : Watch solution here


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