Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C | Loops & Control Structure | Question 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

C




#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;
}

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.
 


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 12 Jan, 2013
Like Article
Save Article
Similar Reads