C Programming Questions and Answers – For Loops – 1

«
»

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.

advertisement

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

Answer: a
Explanation: None.

2. What will be the correct syntax for running two variable for loop simultaneously?
a)

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
   for (i = 0; i < n; i++)
   for (j = 0; j < n; j += 5)

b)

Check this: BCA MCQs | C Books
advertisement
for (i = 0, j = 0; i < n, j < n; i++, j += 5)

c)

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

d) none of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

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

Answer: d
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

Answer: d
Explanation: None.

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         short i;
  5.         for (i = 1; i >= 0; i++)
  6.             printf("%d\n", i);
  7.  
  8.     }

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

Answer: c
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k)
  6.             printf("Hello");
  7.     }

a) Compile time error
b) hello
c) Nothing
d) Varies
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k < 3; k++)
  6.         printf("Hello");
  7.     }

a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
View Answer

Answer: a
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++)
  6.             printf("Hello");
  7.     }

a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
View Answer

Answer: b
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.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.