In C language if I define a value using #define eg:
#define STATE 1
Can I update the value of STATE
further in the program?
If it is possible, tell me how?
In C language if I define a value using #define eg:
#define STATE 1
Can I update the value of STATE
further in the program?
If it is possible, tell me how?
The preprocessor is a text-substitution system. In other words, when you use the symbol STATE
elsewhere in your program it's replaced by its definition, (1
).
For example, if you write:
printf("%d\n", STATE);
The preprocessor replaces STATE
with 1
and what the compiler actually "sees" is:
printf("%d\n", 1);
If you were to try to update STATE
within C code you'd get errors about assigning to an r-value.
If you want to re-define state within the preprocessor, you could do:
#define STATE 1
#undef STATE
#define STATE 2