This set of C Multiple Choice Questions & Answers (MCQs) focuses on “For Loops – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
a) break
b) exit(0)
c) abort()
d) terminate
View Answer
Explanation: None.
2. What will be the correct syntax for running two variable for loop simultaneously?
a)
for (i = 0; i < n; i++) for (j = 0; j < n; j += 5)
b)
for (i = 0, j = 0; i < n, j < n; i++, j += 5)
c)
for (i = 0; i < n;i++){} for (j = 0; j < n;j += 5){}
d) none of the mentioned
View Answer
Explanation: None.
3. Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–)
c) for (i = n-1; i>0; i–)
d) for (i = n-1; i>-1; i–)
View Answer
Explanation: None.
4. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?
a) variable
b) function
c) typedef
d) macros
View Answer
Explanation: None.
5. 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
View Answer
Explanation: None.
6. 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
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
}
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
View Answer
Explanation: None.
8. 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
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.
- Practice BCA MCQs
- Practice Computer Science MCQs
- Check Computer Science Books
- Watch Advanced C Programming Videos
- Apply for C Internship