

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to declare a pointer to a function in C?
A pointer is a variable whose value is the address of another variable or memory block, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable or block address.
Syntax
Datatype *variable_name
Algorithm
Begin. Define a function show. Declare a variable x of the integer datatype. Print the value of varisble x. Declare a pointer p of the integer datatype. Define p as the pointer to the address of show() function. Initialize value to p pointer. End.
This is a simple example in C to understand the concept a pointer to a function.
#include void show(int x) { printf("Value of x is %d\n", x); } int main() { void (*p)(int); // declaring a pointer p = &show; // p is the pointer to the show() (*p)(7); //initializing values. return 0; }
Output
Value of x is 7.
- Related Questions & Answers
- Declare a C/C++ function returning pointer to array of integer function pointers
- How to assign a pointer to function using C program?
- Function pointer to member function in C++
- How to declare a variable in C++?
- How to declare a delegate in C#?
- How to declare a tuple in C#?
- How to declare member function in C# interface?
- Function Pointer in C
- Double Pointer (Pointer to Pointer) in C
- How to declare a global variable in C++
- How to define pointer to pointer in C language?
- Calling a member function on a NULL object pointer in C++
- How to declare and initialize a dictionary in C#?
- How to declare and initialize a list in C#?
- How to declare a two-dimensional array in C#
Advertisements