1,332 views
0 votes
0 votes
#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 ?

1 Answer

2 votes
2 votes

"GeeksQuiz" will be printed only once.

Explanation : 

As we are passing PRINT(i,3) and i=0, 

in IF condition it is comparing if (i++<limit) i.e. if(0<3), it's true

then it goes inside and prints "GeeksQuiz" and then there is a keyword "Continue".

Here is a small catch, Continue statement means it will not execute further statements and return to "Control of loop", Control of loop is where we compare conditions like in for loop it is like "for(i=0;i<n;i++)", in while and do-while it is like "while(i<n)", 

So in this question, after executing "continue" it will directly go to statement "while(0)" which is always FALSE ... so it will come out from the loop.

Source : https://stackoverflow.com/a/2016563

Related questions

0 votes
0 votes
0 answers
1
shiva0 asked Jan 11, 2019
624 views
#include int main() { int i = 1; printf("%d %d %d\n", i++, i++, i); return 0; }
1 votes
1 votes
1 answer
4