Pointer in C++
C++ provides full support for pointers, including pointer arithmetic, double pointers and function pointers. Below is the implementation of pointers in C++:
#include <iostream>
using namespace std;
void geeks()
{
int var = 10;
// declare pointer variable
int* ptr;
// note that data type of ptr and var must be same
ptr = &var;
// assign the address of a variable to a pointer
cout << "Value at ptr = " << ptr << endl;
cout << "Value at var = " << var << endl;
cout << "Value at *ptr =" << *ptr << endl;
}
// Driver program
int main()
{
geeks();
return 0;
}
Output
Value at ptr = 0x7fff078bd004 Value at var = 10 Value at *ptr =10
Pointer in programming
Pointer is a variable that stores the memory address of another variable. Pointers are a powerful feature of many programming languages, including C, C++, and others. They provide a way to simulate call-by-reference, create complex data structures, and interact with the operating system.