What is pointers?
- Pointer is a variable that points to an address of a value.
- Pointer is a variable that stores the address of another variable.
- Pointer is used to allocate memory at run time i.e dynamically.
Symbols used in Pointer :
- & (ampersand sign) : ‘Address of operator’
- Determines the address of a variable.
- * (asterisk sign) : indirection operator / value at address
- * Accesses the value at the address.
Syntax :
Datatype *variable_name;
Example :
#include <iostream>
using namespace std;
int main ()
{
int a = 320;
int *b;
b = &a;
cout << "Value of a variable is : ";
cout << a << endl;
cout << "Address stored in b variable is: ";
cout << b << endl;
cout << "Value of *b variable is : ";
cout << *b << endl;
return 0;
}
Output :
Value of a variable is : 320
Address stored in b variable is: 0x68fee8
Value of *b variable is : 320
Note : Pointer variable value should be integer (address).
C Plus Plus program to create a class complex through pointers
C++ program to create a class complex through pointers
