Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
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
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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;
}

Output

bar
foo

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;
}

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!

Previous article
exit() vs _Exit()
Next article
Callback Function in C
Live masterclass