github

Made bySaurav Hathi

MCQ Test C/C++: Loops and Controls

Q1:

Does this C code compile without error?

#include <stdio.h>

int main()

{

for (int k = 0; k < 10; k++);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q2:

Does this C code compile without error?

#include <stdio.h>

int main()

{

int k;

{

int k;

for (k = 0; k < 10; k++);

}

}

Tags:
Section:
Core Programming
Options:
Q3:

Comment on the output of this C code?

#include <stdio.h>

int main()

{

int i, n, a = 4;

scanf("%d", &n);

for (i = 0; i < n; i++)

a = a * 2;

}

Tags:
Section:
Core Programming
Options:
Q4:

The following code ‘for(;;)’ in C/C++ represents an infinite loop. It can be terminated by __________ statement.

Tags:
Section:
Core Programming
Options:
Q5:

Which for loop has range of similar indices of ‘i’ used in for (i = 0;i < n; i++) in C/C++?

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this C code?

#include <stdio.h>

int main()

{

short i;

for (i = 1; i >= 0; i++)

printf("%d\n", i);

}

Tags:
Section:
Core Programming
Options:
Q7:

What is the output of this C code?

#include <stdio.h>

int main()

{

int k = 0;

for (k < 3; k++)

printf("Hello");

}

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this C code?

#include <stdio.h>

int main()

{

while ()

printf("In while loop ");

printf("After loop\n");

}

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 0;

do {

i++;

printf("In while loop\n");

} while (i < 3);

}

Tags:
Section:
Core Programming
Options:
Q10:

How many times value of i is checked in the below C code?

#include <stdio.h>

int main()

{

int i = 0;

do {

i++;

printf("in while loop\n");

} while (i < 3);

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this C code?

#include <stdio.h>

int main()

{

int a = 0, i = 0;

for (i = 0;i < 5; i++)

{

a++;

continue;

}

printf("%d",a);

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 0, j = 0;

for (i = 0;i < 5; i++)

{

for (j = 0;j < 4; j++)

{

if (i > 1)

break;

}

printf("Hi \n");

}

}

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of the C code given below?

#include <stdio.h>

int main()

{

printf("%d ", 1);

goto l1;

printf("%d ", 2);

l1:goto l2;

printf("%d ", 3);

l2:printf("%d ", 4);

}

Tags:
Section:
Core Programming
Options:
Q14:

What is output of C code given below?

#include <stdio.h>

int main()

{

int i = 0, j = 0;

while (i < 2)

{

l1 : i++;

while (j < 3)

{

printf("Loop\n");

goto l1;

}

}

}

Tags:
Section:
Core Programming
Options: