Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How memory is allocated to macros in c?

I would like to know how the memory is allocated to #define variables in C.

#define VAR1 10

I have 2 questions...

  1. What's the type of VAR1?
  2. In which memory segment VAR1 is stored?
like image 502
Sagar Jain Avatar asked Dec 02 '25 23:12

Sagar Jain


1 Answers

In which memory segment VAR1 is stored?

In none of the segment.

VAR1 is relevant only in pre-processing stage and does not have any identity at run time. During pre-processing all instances of VAR1 are replaced with 10 so there is no memory requirement at run time because 10 is an integer literal.

What's the type of VAR1?

VAR1 is replaced with 10 at pre-processing stage. 10 being an integer literal, we can say type or VAR1 is int.


Moral: Macros are not variables.

like image 55
Mohit Jain Avatar answered Dec 04 '25 12:12

Mohit Jain