C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - True / False Questions (Q.No. 7)
7.
Macros have a local scope.
Answer: Option
Explanation:
False, The scope of macros is globals and functions. Also the scope of macros is only from the point of definition to the end of the file.
Discussion:
2 comments Page 1 of 1.
Nitesh said:
4 years ago
@John
As we know when we use a global variable then it works throughOut the Programme So here is also the same Concept Applies When we use Macro it Works throughout the programme.
I leave one example as below:
# define i 20
void fun(){
#undef i
#define i 30
}
int main(){
printf("%d",i);
fun();
printf(" %d",i);
return 0;
}
Output:30 30.
As we know when we use a global variable then it works throughOut the Programme So here is also the same Concept Applies When we use Macro it Works throughout the programme.
I leave one example as below:
# define i 20
void fun(){
#undef i
#define i 30
}
int main(){
printf("%d",i);
fun();
printf(" %d",i);
return 0;
}
Output:30 30.
Elder John said:
8 years ago
Why shouldn't it be Ture?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers