TCS NQT Questions on Loops Quiz– 1

Question 1

Time: 00:00:00
The output of the code below is ?
#include <stdio.h>
int a;
void main()
{
if (a)
printf(“Hello”);
else
printf(“world”);
}

Hello

Hello

world

world

compile time error

compile time error

none

none

Question 2

Time: 00:00:00
The output of the code below is

#include <stdio.h>
void main()
{
int a = 5;
if (true);
printf(“hello”);
}

It will display hello

It will display hello

It will throw an error

It will throw an error

No Output

No Output

Depends on Compiler

Depends on Compiler

Question 3

Time: 00:00:00
The output of the code below is
#include <stdio.h>
void main()
{
int a = 0;
if (a == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}

hi

hi

how are you

how are you

hello

hello

hihello

hihello

Question 4

Time: 00:00:00
The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.

break

break

exit(0)

exit(0)

abort()

abort()

all of the mentioned

all of the mentioned

Question 5

Time: 00:00:00
The correct syntax for running two variable for loop simultaneously is.

a) for (i = 0; i < n; i++) for (j = 0; j < n; j += 5)

a) for (i = 0; i < n; i++) for (j = 0; j < n; j += 5)

for (i = 0, j = 0;i < n, j < n; i++, j += 5)

for (i = 0, j = 0;i < n, j < n; i++, j += 5)

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

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

for (j = 0; j < n;j += 5){}

for (j = 0; j < n;j += 5){}

Question 6

Time: 00:00:00
Which for loop has range of similar indexes of ‘i’ used in

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

for (i = n; i>0; i--)

for (i = n; i>0; i--)

for (i = n; i >= 0; i--)

for (i = n; i >= 0; i--)

for (i = n-1; i>0; i--)

for (i = n-1; i>0; i--)

for (i = n-1; i>-1; i--)

for (i = n-1; i>-1; i--)

Question 7

Time: 00:00:00
The output of this C code is?

#include <stdio.h>
void main()
{
int x = 0;
for (x < 3; x++)
{
printf(“Hello”);
}
}

Compile time error

Compile time error

Hello is printed thrice

Hello is printed thrice

Nothing

Nothing

Varies

Varies

Question 8

Time: 00:00:00
The output of this C code is?

#include <stdio.h>
void main()
{
double x = 0;
for (x = 0.0; x < 3.0; x++)
printf(“Hello”);
}

Run time error

Run time error

Hello is printed thrice

Hello is printed thrice

Hello is printed twice

Hello is printed twice

Hello is printed infinitely

Hello is printed infinitely

Question 9

Time: 00:00:00
The output of this C code is?

#include <stdio.h>
int main()
{
do{
printf(“Inside while loop “);
}while (0);
printf(“Outside loop\n”);
}

Inside while loop

Inside while loop

Inside while loop Outside loop

Inside while loop Outside loop

Outside loop

Outside loop

Infinite loop

Infinite loop

Question 10

Time: 00:00:00
The output of this C code is?

#include <stdio.h>
int main()
{
int i = 0;
do {
i++;
printf(“Inside while loop\n”);
} while (i < 3);
}

Inside while loop will be printed thrice.

Inside while loop will be printed thrice.

Outside while loop

Outside while loop

Depends on the compiler

Depends on the compiler

Compile time error

Compile time error

null
null

Buy TCS NQT Paid Materials

Paid Materials TCS NQT

Join TCS NQT Online Classes