Q:

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

belongs to collection: C Preprocessors Programs

0

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

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))

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Define Macros to SET and CLEAR bit of a PIN in C... >>
<< Define a function like Macro that should use print...