Q:

C program to print the function names defined in the source code

belongs to collection: C Preprocessors Programs

0

C program to print the function names defined in the source code

 

All Answers

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

In this program, we will use __FUNCTION__ macro to print the function name, also we will print all function names defined in the source code.

__FUNCTION__ Macro:

This macro is used to return the current function name. It is useful for debugging i.e., to generate the logs.

Program:

The source code to print the function names defined in the source code is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to print the function names
// defined in source code

#include <stdio.h>

void func1()
{
    printf("%s\n", __FUNCTION__);
}

void func2()
{
    printf("%s\n", __FUNCTION__);
}

void func3()
{
    printf("%s\n", __FUNCTION__);
}

int main()
{
    printf("Function are: \n");

    func1();
    func2();
    func3();

    printf("%s\n", __FUNCTION__);

    return 0;
}

Output:

Function are: 
func1
func2
func3
main

Explanation:

In the main() function, we called func1()func2()func3() function and print the function names using __FUNCTION__ macro on the console screen.

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
C program to print the name of the source code fil... >>
<< Define a Macro to round a float value to nearest i...