MCQs on Conditional Statements & Loops - C Programming Multiple Choice questions with answers

Sports GK Questions and Answers 2024 (Latest Updated)

Awards & Honours GK Questions 2024 (Latest Updated)

Questions
11 If the following loop is implemented

void main()
{ 
	int num = 0;
	do
	{
		- - num;
		printf (“%d”, num);
		num ++;
	}
	while (num >=0);	
}
A A run time error will be reported
B The program will not enter into the loop
C The loop will run infinitely many times
D There will be a compilation error reported

Answer: Option [C]
12 Consider the following code snippet

marks = 80;
switch (marks)
{
	case 60:
	grade = ‘C’;
	break;
	case 70: 
	grade = ‘B’;
	break;
	case 80:
	grade = ‘A’;
	break;
	default:
	grade = ‘E’;
}

What is the value of ‘grade’ after the switch statement is executed?

A A
B B
C C
D E

Answer: Option [A]
Advertisement
Article and Schedule Quiz Start Test!
DOWNLOAD CURRENT AFFAIRS PDF FROM APP
13 Consider the following program fragment:
switch (input)
{
	case ‘1’: printf (“one”);
	case ‘3’: printf (“three”);
	case ‘4’: printf (“five”);
	default: printf (“odd”); break;
}

What will be printed when input is ‘3’?

A Three five odd
B Three
C Three odd
D Three odd

Answer: Option [B]
14 Consider the following code fragment

for(digit = 0; digit < 9; digit++)
{
	digit = 2*digit;
	digit - -;
}

How many times the loop will be executed?

A Infinite
B 9
C 5
D 0

Answer: Option [A]
15 The following program segment

{
	int sum, index;
	index = 50;
	while (index > = 0) 
	{
		sum =sum/index;
		-index;
	}
} 
A Will give a run time error
B Will give a compilation error
C Will give a linking error
D None of the above

Answer: Option [B]
16 The output of the following code segment will be

char x = ‘B’
switch (x) 
{
	case ‘A’ : printf (“a”);
	case ‘B’ : printf (“b”);
	default  : printf (“c”);
}
A B
B a
C C
D b

Answer: Option [D]

Random GK Questions

Chapters

Assam Direct Recruitment Test Series

Computer Science Topics