Aarav Kandara
last year
Aaravcountry asked

What is the difference between a macro and a variable in C?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Aarav,

A macro is a text replacement done before compilation using #define. It does not create a real variable in memory.

#define PI 3.14

A variable is a real storage location in memory with a type, and its value can change while the program runs.

float pi = 3.14;

So the simple difference is: macros are replaced in the code, variables store values in memory.

If you have more questions, I am here to help 😊

C
This question was asked as part of the Learn C Programming course.