0

What is the function pointers in c++? Please explain and give examples

29th Dec 2016, 11:37 PM
ahmad syarifudin mahzumi
ahmad syarifudin mahzumi - avatar
2 Respostas
+ 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
30th Dec 2016, 2:03 AM
Andreas K
Andreas K - avatar
0
thank
30th Dec 2016, 2:31 AM
ahmad syarifudin mahzumi
ahmad syarifudin mahzumi - avatar