Pointers in C++
Pointers in C++
POINTERS
• DEFINITION:
A pointer is a variable that holds a memory addrress of another variable.
asterisk symbol:(*)
• CREATE POINTER:
data_type * pointer_name;
ex: int* ptr;
• ASSIGN ADDRESS:
address of operator:(&)
ex: int var = 10;
int * ptr = &var;
cout<<*ptr; // output: 10
cout<<ptr; // output: 0x7fffa0757dd4
HOW POINTER WORKS?
EXAMPLE
#include <iostream>
using namespace std;
int main()
{
int x = 10; // variable declared
int* myptr; // pointer variable
return 0;
}
OUTPUT
Value of x is: 10
Address stored in myptr is: 0x7ffd2b32c7f4
Value of x using *myptr is: 10
THANK YOU