ADVERTISEMENT
ADVERTISEMENT

Print the current function name by using __func__ in C | C preprocessor programs

Here, we are going to learn how to print the name of the current function in C programming language? To print the name of current function, we use __func__ macro.
Submitted by IncludeHelp, on August 29, 2018

Macro: __func__

__func__ is the predefine macro, and it is used to get the name of the current function. This macro is added in C99.

Example:

#include <stdio.h>

//fun1
void fun1(void){
	printf("Called function is: %s\n",__func__);
}

//fun2
void fun2(void){
	printf("Called function is: %s\n",__func__);
}

//Main code
int main(){
	
	printf("Called function is: %s\n",__func__);
	//function callings
	printf("Now,calling the functions...\n");
	fun1();
	fun2();
	
	return 0;	
}

Output

    Called function is: main
    Now,calling the functions...
    Called function is: fun1
    Called function is: fun2

C Preprocessors Programs »


ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

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.