Q:

Print argument (i.e. variable name, value) using Macro in C

belongs to collection: C Preprocessors Programs

0

Print argument (i.e. variable name, value) using Macro in C

All Answers

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

Example:

#include <stdio.h>

#define SQUARE(N)	printf("Square of " #N " is = %d\n",(N*N))
#define CUBE(N)		printf("Cube   of " #N " is = %d\n",(N*N*N))

int main()
{
	int number = 10;
	
	//passing variable name 
	SQUARE(number);
	CUBE(number);
	
	//passing values
	SQUARE(10);
	CUBE(10);

	return 0;
}

Output

    Square of number is = 100
    Cube   of number is = 1000
    Square of 10 is = 100
    Cube   of 10 is = 1000

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
Print error message from any function with functio... >>
<< How to check whether a Macro is defined or not in ...