0
What is the function pointers in c++? Please explain and give examples
2 Respuestas
+ 1
Pointers address the memory space to specific values.
example :
int i = 5;
int* p = &i ;
std::cout << i << std::endl; // prints 5
std::cout << p << std::endl; //prints the address where I is stored in the memory
std::cout << *p << std::endl; // prints the value at the address, so it prints 5
A main use for this can be at the use of arrays. Cause standard C arrays are nothing more than a pointeron its first element. This means you can do following:
int arr = {1,2,3};
int* p = arr;
std::cout << arr[1] << std::endl; // prints 2
std::cout << *(p+1) << std::endl; // prints 2 aswell
0
thank