C | Loops & Control Structure | Question 2
#include <stdio.h> #define PRINT(i, limit) do \ { \ if (i++ < limit) \ { \ printf("GeeksQuiz\n"); \ continue; \ } \ }while(0) int main() { int i = 0; PRINT(i, 3); return 0; } |
chevron_right
filter_none
How many times GeeksQuiz is printed in the above program ?
(A) 1
(B) 3
(C) 4
(D) Compile-time error
Answer: (A)
Explanation: If a macro needs to be expanded in multiple lines, it is the best practice to write those lines within do{ }while(0) to avoid macro side effects. After GeeksQuiz is printed once, the control reaches the while statement to check for the condition. Since, the condition is false, the loop gets terminated.
Recommended Posts:
- C | Loops & Control Structure | Question 18
- C | Loops & Control Structure | Question 8
- C | Loops & Control Structure | Question 1
- C | Loops & Control Structure | Question 12
- C | Loops & Control Structure | Question 19
- C | Loops & Control Structure | Question 13
- C | Loops & Control Structure | Question 10
- C | Loops & Control Structure | Question 14
- C | Loops & Control Structure | Question 11
- C | Loops & Control Structure | Question 15
- C | Loops & Control Structure | Question 16
- C | Loops & Control Structure | Question 17
- C | Loops & Control Structure | Question 21
- C | Loops & Control Structure | Question 9
- C | Loops & Control Structure | Question 20



