C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - Point Out Errors (Q.No. 2)
2.
Point out the error in the program
#include<stdio.h>
int main()
{
int i;
#if A
printf("Enter any number:");
scanf("%d", &i);
#elif B
printf("The number is odd");
return 0;
}
Answer: Option
Explanation:
The conditional macro #if must have an #endif. In this program there is no #endif statement written.
Discussion:
10 comments Page 1 of 1.
Rohan said:
6 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.
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:
10 years ago
@Jagadesh.
Infinite loop as the for loop will execute infinite number of scanf statements and therefore printf also. If still doubt, do comment. :).
Infinite loop as the for loop will execute infinite number of scanf statements and therefore printf also. If still doubt, do comment. :).
Jagadesh said:
1 decade ago
int main ( )
{
int i;
for(;scanf("%d",&i);printf("%d",i));
return 0;
}
Can any one give me the output?
{
int i;
for(;scanf("%d",&i);printf("%d",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:
8 years ago
Hii friends.
You are right @Shekhar. It gives an infinite loop.
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:
3 years ago
@Rohan.
Very good explanation, Thanks.
Very good explanation, Thanks.
Shubh said:
5 years ago
What is the A and B means?
Ritik said:
4 years ago
A and B are macros @Shubh.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers