Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Pointer to a Function is an address of a function in memory [C/C++]

Pointer to a Function is an address of a function in memory [C/C++]

This is a C program of showing how to use a pointer to a function. The pointer to a function is available in ANSI-C as well as in C++ and works as described in this program. It is not regularly used by most C programmers, so it is defined here as a refresher.

A pointer to a function is a type of pointer that points to the address of a function in memory. A function pointer is declared using the syntax return_type (*function_pointer_name)(argument_list). To call a function through a function pointer, you need to dereference it using the (*function_pointer_name) syntax and pass the required arguments in the parentheses.

Review our article titled Working with Pointers in C for a detailed discussion about pointers and how to use them in your C programs.

Beginning C++23
Kickstart your coding journey with Beginning C++23 – the ultimate guide to mastering the latest in modern C++ programming!
View on Amazon

Output of the C Program:

 

About The Author

M. Saqib

Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.