Define Macro PRINT to print given integer argument in C | C preprocessor programs

Here, we will learn how to print an integer value which is passed in macro definition in C language?
By IncludeHelp Last updated : March 10, 2024

As we have discussed in the last post (how to use printf in function like macro?) that we can use printf() in Macros.

Here, we have to define a Macro that will accept an argument and print it by using printf() function.

Macro definition

    #define PRINT(val) (printf("value is: %d\n",val))

Example

#include <stdio.h>

#define PRINT(val) (printf("value is: %d\n",val))

//Main code
int main(){
	
	PRINT(10);
	PRINT(100);
	PRINT(-12);
	PRINT(0);
	
	return 0;	
}

Output

value is: 10
value is: 100
value is: -12
value is: 0

C Preprocessors Programs »


Comments and Discussions!

Load comments ↻






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