Table of contents
1.
Introduction
2.
Predefined Identifier in C
3.
Predefined Identifier __func__ in C
3.1.
Example 1
3.2.
Example 2
4.
Frequently Asked Questions
4.1.
Is it necessary to add __func__ predefined identifier?
4.2.
Does __func__ methods works on the main function also?
4.3.
In which C language standard is the predefined identifier __func__ implicitly called?
5.
Conclusion
Last Updated: Mar 27, 2024

Predefined Identifier __func__ in C

Author Rhythm Jain
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Before learning about predefined identifiers, let's know about what identifier is.

In programming, the identifier is the name provided to an entity to identify it within the program. Let us learn more about Predefined Idenfier __func__ in C.

Also see : C Static Function, Tribonacci Series

Predefined Identifier in C

Identifiers are often developed by programmers for efficiency, although there are also predetermined identifiers integrated into programming—for example, cout, cin, etc.

Predefined Identifier __func__ in C

__func__ is one of the predefined identifiers of the C programming language.

According to the C language standard (C99 and C11), the C compiler implicitly adds __func__ in every function to be used in that function to get the function name.

It is Implicitly declared by the translator as if static const char __func__[] = "function-name" appeared immediately before the opening brace of each function definition.

Example 1

#include <stdio.h>
void foo(void){
   printf ("%s\n", __func__);
}
void bar (void){
   printf ("%s\n", __func__);
   foo ();
}
int main (){
   bar ();
   return 0;
}

You can also try this code with Online C Compiler
Run Code

Output

bar
foo
You can also try this code with Online C Compiler
Run Code

In this example, the __func__ method was used to return the names of the functions that were called. The identifier returns the name of the function that was called.

Example 2

#include <stdio.h>
   
int main (){
   printf ("%s\n", __func__);
   return 0;
}
You can also try this code with Online C Compiler
Run Code

Output

main

Here __func__ identifier is used to get the name of the main function.
 

Also see,  Short int in C Programming

Frequently Asked Questions

Is it necessary to add __func__ predefined identifier?

No, it is not necessary to add Predefined Identifier __func__ in C . the compiler implicitly adds it by default.

Does __func__ methods works on the main function also?

Yes, the __func__ identifier can be used to get the name of the main function also.

In which C language standard is the predefined identifier __func__ implicitly called?

In C language standards C99 and C11, the predefined identifier __func__ implicitly called for each function.

Conclusion

In this article, we have extensively discussed Predefined Identifier __func__ in C and its examples. If you want to learn about the operating systems and file structures in C, you can visit Operating SystemUnix File SystemFile System Routing, and File Input/Output.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc.; you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass