Please Turn On Java Script To Access This Site.

C Institute | Questions


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

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

Q1: The keyword ‘break’ can be simply used within _________
a)  do while
b)  switch
c)  break
d)  all of these
Correct Answer : d
Explanation : The break keyword can be used inside the for,while, do while and switch statement.
Learn the working of break and continue


Q2: The continue keyword can not be used within
a)  for
b)  do while
c)  switch
d)  while
Correct Answer : c
Explanation : The continue statement can be used within loops only.
Learn continue statement


Q3: what will be the output of compiling and executing the below c code?
#include<stdio.h>
int main()
{	int k=1;
	while(k<10)
	{	if(k++>5)
			break;
		printf("%d ",k);
	}
	return 0;
}
a)  1 2 3 4 5
b)  2 3 4 5
c)  1 2 3 4 5 6
d)  2 3 4 5 6
Correct Answer : d
Explanation : Watch solution here


Q4: what will be the output of compiling and executing the below c code?
#include<stdio.h>
int main()
{	int k=1;
	for(;k<10;k++)
	{	if(k++>5)
			break;
		printf("%d ",k);
	}
	return 0;
}
a)  1 2 3 4 5
b)  2 4 6
c)  2 4 6 8
d)  2 3 4 5 6
Correct Answer : b
Explanation : Watch solution here


Q5: what will be the output of compiling and executing the below c code?
#include<stdio.h>
int main()
{	int k=1;
	do
	{	if(k++>=5)
			break;
		printf("%d ",k);
	}while(k);
	return 0;
}
a)  1 2 3 4 5
b)  2 3 4 5 6
c)  2 3 4 5
d)  Infinite loop
Correct Answer : c
Explanation : Watch solution here


Q6: what will be the output of compiling and/or executing the below c code?
#include<stdio.h>
int main()
{	int k=1;
	if(k<=5)
	{	if(k==2)
			break;
		printf("%d ",k);
		k++;
	}
	return 0;
}
a)  2 3
b)  1 2 3 4 5
c)  Syntax Error
d)  None of these
Correct Answer : c
Explanation : break is not inside loop or switch, so this is syntax error while compilation.
Learn c in hindi
Watch solution here


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