C Programming - C Preprocessor - Discussion


Will the following program print the message infinite number of times?

#define INFINITELOOP while(1)

int main()
    return 0;

[A]. Yes
[B]. No

Answer: Option A


Yes, the program prints "IndiaBIX" and runs infinitely.

The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)'

In the main function, while(1) satisfies the while condition and it prints "IndiaBIX". Then it comes to while(1) and the loop runs infinitely.

Raman said: (May 1, 2014)  
There is something called "stack overflow" Why do you pose such ambiguous questions?

Bhumica said: (Aug 17, 2014)  
what would have been the answer, if instead of while(1) it was while(0)?

Abhayraj SN said: (Aug 24, 2016)  
@Bhumica, In case of while (0) the condition of while loop is false (0 = false). Hence while loop is not executed, so NOTHING will be printed.

Someone may correct or modify me.

Piya Raichand said: (Sep 15, 2016)  
What you said is correct @Abhayraj. No modifications required.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.