C Looping Statements Objective Questions:
What is an example of iteration in C?
A) for
B) while
C) do-while
D) all of the mentioned
ANSWER:D
The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
A) break
B) exit(0)
C) abort()
D) terminate
ANSWER:A
The syntax of a for loop in C programming is:
for (initialization; condition;updation){ statements;}
for (initialization; condition ){ statements;}
for (initialization;){ statements;}
for (initialization; adjustment){ statements;}
ANSWER:A
Which of following is entry control loop?
A)do while
B)while
C)for loop
D)None of the above
ANSWER:B
Which of following is exit control loop?
A)do while
B)while
C)for loop
D)None of the above
ANSWER:A
What will be the output of following code
int main()
int i = 1 ;
while( i<=2)
printf("%d",i);
return 0;
A)12
B)i
C)Compillation error
D)Infinite loop
ANSWER:D
When _________ is encountered inside any loop, Control automatically passes to the first
statement after loop.
A) Continue
B) break
C) goto
D) return
ANSWER:B
What will be the output of the following C code?
#include <stdio.h>
int main()
short i;
for (i = 1; i >= 0; i++)
printf("%d\n", i);
A)The control won’t fall into the for loop
B) Numbers will be displayed until the signed limit of short and throw a runtime error
C) Numbers will be displayed until the signed limit of short and program will successfully
terminate
D) This program will get into an infinite loop and keep printing numbers with no errors
ANSWER:C
What will be the output of the following C code?
#include <stdio.h>
void main()
int k = 0;
for (k)
printf("Hello");
A)Compile time error
B) hello
C) Nothing
D) Varies
ANSWER:C
What will be the output of the following C code?
#include <stdio.h>
void main()
double k = 0;
for (k = 0.0; k < 3.0; k++)
printf("Hello");
A)Run time error
B) Hello is printed thrice
C) Hello is printed twice
D) Hello is printed infinitely
ANSWER:B
++ operator used within Loops increment the value of variable by
A)0
B1
C)Run time error
D) depends on the compiler
ANSWER:B
What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0;
do {
i++;
printf("In while loop\n");
} while (i < 3);
A) In while loop In while loop In while loop
B) In while loop In while loop
C) Depends on the compiler
D) Compile time error
ANSWER:A
What will be the output of the following C code?
#include <stdio.h>
void main() {
int i = 0;
while (++i)
{ printf("H");
} }
A) H
B) H is printed infinite times
C) Compile time error
D) Varies
ANSWER: B
Choose correct C while loop syntax.
A) while(condition) { //statements }
B) { //statements } while(condition)
C) while(condition); { //statements }
D) while() { if(condition) { //statements }}
ANSWER:A
What is the output of C Program.?
int main()
{ int a=25;
while(a <= 27)
printf("%d ", a);
a++; }
return 0;}
A) 25 25 25
B) 25 26 27
C) 27 27 27
D) Compiler error
ANSWER:B
What is the output of C Program.?
int main()
{ int a=32;
do
{ printf("%d ", a);
a++;
}while(a <= 30);
return 0;
A) 32
B) 33
C) 30
D) No Output
ANSWER:A
What is the output of C Program.?
int main()
{ int k, j;
for(k=1, j=10; k <= 5; k++)
{ printf("%d ", (k+j));
} return 0;
A) compiler error
B) 10 10 10 10 10
C) 11 12 13 14 15
D) None of the above
ANSWER:C
What is the output of C Program.?
int main()
{ int k;
for(k=1; k <= 5; k++);
{ printf("%d ", k);
return 0;
A) 1 2 3 4 5
B) 1 2 3 4
C) 6
D) 5
ANSWER:C
What is the output of C Program.?
int main()
{ int k;
for(;;)
printf("TESTING\n");
break;
} return 0;
A) No Output
B) TESTING
C) Compiler error
D) None of the above
ANSWER:B
What is the way to suddenly come out of or Quit any Loop in C Language.?
A) continue; statement
B) break; statement
C) leave; statement
D) quit; statement
ANSWER:B
What is the output of C Program.?
int main()
{ int a=10, b, c;
b=a++;
c=++a;
printf("%d %d %d", a, b, c);
return 0;
A) 10 11 12
B) 12 10 12
C) 12 11 12
D) 12 12 12
ANSWER:B
What is the output of C Program.?
int main()
int a=0, b=0;
while(++a < 4)
printf("%d ", a);
while(b++ < 4)
printf("%d ", b);
return 0;
}
A) 0 1 2 3 1 2 3 4
B) 1 2 3 1 2 3 4
C) 1 2 3 4 1 2 3 4
D) 1 2 3 4 0 1 2 3
ANSWER:B
What is the output of C Program.?
int main()
{ int a=10,b=20;
if(a==9 AND b==20)
{ printf("Hurray..");
} if(a==10 OR b==21)
{ printf("Theatre");
} return 0;}
A) Theatre
B) Hurray Theatre
C) No output
D) Compiler error
ANSWER:D
Choose a correct statement about C break; statement.?
A) break; statement can be used inside switch block
B) break; statement can be used with loops like for, while and do while.
C) break; statement causes only the same or inner loop where break; is present to quit suddenly.
D) All the above.
ANSWER:D
Choose a correct C Statement regarding for loop.
for(; ;);
A) for loop works exactly first time
B) for loop works infinite number of times
C) Compiler error
D) None of the above
ANSWER:B