This set of C Multiple Choice Questions & Answers (MCQs) focuses on “For Loops – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. 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("%lf", k);
}
a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int k;
for (k = -3; k < -5; k++)
printf("Hello");
}
a) Hello
b) Infinite hello
c) Run time error
d) Nothing
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
for (; ; ;)
printf("In for loop\n");
printf("After loop\n");
}
a) Compile time error
b) Infinite loop
c) After loop
d) Undefined behaviour
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
for (i++; i == 1; i = 2)
printf("In for loop ");
printf("After loop\n");
}
a) In for loop after loop
b) After loop
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
a) After loop
b) In for loop after loop
c) Compile time error
d) Infinite loop
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int *p = NULL;
for (foo(); p; p = 0)
printf("In for loop\n");
printf("After loop\n");
}
a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
for (int i = 0;i < 1; i++)
printf("In for loop\n");
}
a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Run time error
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Watch Advanced C Programming Videos
- Apply for C Internship
- Buy Computer Science Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs