ADVERTISEMENT
ADVERTISEMENT

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

Here, we will learn how to print the given argument like variable name, value using Macro in C programming language?
Submitted by IncludeHelp, on September 01, 2018

To print argument (which is passed as Macro argument), we use # operator in C programming language. # prints the passed argument as it is, it may be a variable name, value etc.

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

C Preprocessors Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.