Q:

Define a function like Macro that should use printf in C | C preprocessor programs

belongs to collection: C Preprocessors Programs

0

Define a function like Macro that should use printf in C | C preprocessor programs

We can use printf() function in a Macro. In this example, we are creating a function like Macro that will print the result of a calculation, like adding two numbers.

Macro definition:

 #define SUM(a,b) (printf("SUM of %d and %d is = %d\n", a, b, a+b))

 

All Answers

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

Example:

#include <stdio.h>

#define	SUM(a,b)	(printf("SUM of %d and %d is = %d\n", a, b, a+b))

//Main code
int main(){
	
	//adding 10 and 20
	SUM(10,20);
	//adfing 100 and 200
	SUM(100,200);
	
	return 0;	
}

Output

    SUM of 10 and 20 is = 30
    SUM of 100 and 200 is = 300

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 Macro PRINT to print given integer argument... >>
<< Define Macros for YES and NO constants using #defi...