How to redefine a Macro in C?

Here, we are going to learn how to redefine a defined Macro in C programming language? To redefine a Macro, first we undefined the Macro and then define the Macro.
By IncludeHelp Last updated : March 10, 2024

Redefining a Macro in C

The process to redefine a Macro is:

  1. Macro must be defined.
  2. When, you want to redefine the Macro, first of all, undefined the Macro by using #undef preprocessor directive.
  3. And, then define the Macro again by using #define preprocessor directive.

Example

#include <stdio.h>

#define NUM 100

int main()
{
	//printing the value of NUM
	printf("NUM: %d\n", NUM);
		
	//redefining the Macor: NUM 
	#undef NUM
	#define NUM 200
	
	//printing the value of NUM 
	printf("NUM: %d\n", NUM);
	
	return 0;
}

Output

NUM: 100
NUM: 200

C Preprocessors Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.