C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - Point Out Errors (Q.No. 2)
Point out the error in the program

int main()
    int i;
    #if A
        printf("Enter any number:");
        scanf("%d", &i);
    #elif B
        printf("The number is odd");
    return 0;
Error: unexpected end of file because there is no matching #endif
The number is odd
Garbage values
None of above
Answer: Option

The conditional macro #if must have an #endif. In this program there is no #endif statement written.

10 comments Page 1 of 1.

Rohan said:   5 years ago
Here it is;

int i;
Step 1: a variable(i) is declared.

#if A
printf("Enter any number:");
scanf("%d", &i);
Step 2: (i) Macro() or preprocessor can be used inside main() function..
(ii) It will execute the if condition

#elif B
printf("The number is odd");

Step 3: It will execute elif part too but #endif is missing from this program and so it will give an error.

SHEKHAR said:   9 years ago

Infinite loop as the for loop will execute infinite number of scanf statements and therefore printf also. If still doubt, do comment. :).

Jagadesh said:   9 years ago
int main ( )
int i;

return 0;

Can any one give me the output?

Preeti said:   1 decade ago
Yes I think. Because the above program gives output without errors when elif is replaced by endif.

Vishalakshi said:   7 years ago
Hii friends.

You are right @Shekhar. It gives an infinite loop.

Meena said:   1 decade ago
Can we include the prreprocessors inside the program?

Huma said:   1 decade ago
Yes we can define macros within main().

Amol pansare said:   2 years ago

Very good explanation, Thanks.

Shubh said:   4 years ago
What is the A and B means?

Ritik said:   3 years ago
A and B are macros @Shubh.

Post your comments here:

Your comments will be displayed after verification.