C Programming - C Preprocessor - Discussion

7. 

Macros have a local scope.

[A]. True
[B]. False

Answer: Option B

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.


Elder John said: (Mar 12, 2017)  
Why shouldn't it be Ture?

Nitesh said: (Dec 5, 2020)  
@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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.