C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - Yes / No Questions (Q.No. 6)
6.
Will the following program print the message infinite number of times?
#include<stdio.h>
#define INFINITELOOP while(1)

int main()
{
    INFINITELOOP
    printf("IndiaBIX");
    return 0;
}
Yes
No
Answer: Option
Explanation:

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.

Discussion:
4 comments Page 1 of 1.

Raman said:   1 decade ago
There is something called "stack overflow" Why do you pose such ambiguous questions?

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

Abhayraj SN said:   9 years ago
@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:   9 years ago
What you said is correct @Abhayraj. No modifications required.

Post your comments here:

Your comments will be displayed after verification.