1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-25 18:20:46 +02:00

Add information about function pointer (#4460)

This commit is contained in:
Kirill Bryntsev
2023-09-12 22:30:27 +07:00
committed by GitHub
parent 79a656e171
commit 072953c69a

View File

@@ -19,6 +19,20 @@ int *ptr = # // Pointer 'ptr' now points to the memory address of 'num'
int value = *ptr; // Value now contains the value of the variable that 'ptr' points to (i.e., 10)
```
**Function pointer:**
```cpp
int add(int a, int b)
{
return a + b;
}
int main()
{ int (*funcptr) (int, int) = add; // Pointer 'funcptr' now points to the functions 'add'
funcptr(4, 5); // Return 9
}
```
## References
A reference is an alias for an existing variable, meaning it's a different name for the same memory location. Unlike pointers, references cannot be null, and they must be initialized when they are declared. Once a reference is initialized, it cannot be changed to refer to another variable.