0% found this document useful (0 votes)
8 views6 pages

Pointers in C++

This document explains pointers in C++, defining them as variables that hold memory addresses of other variables. It provides examples of how to create a pointer, assign an address using the address-of operator, and demonstrates pointer usage in a sample code. The output of the code illustrates how to access variable values and addresses through pointers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Pointers in C++

This document explains pointers in C++, defining them as variables that hold memory addresses of other variables. It provides examples of how to create a pointer, assign an address using the address-of operator, and demonstrates pointer usage in a sample code. The output of the code illustrates how to access variable values and addresses through pointers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

// storing address of x in pointer myptr


myptr = &x;

cout << "Value of x is: ";


cout << x << endl;

// print the address stored in myptr pointer variable


cout << "Address stored in myptr is: ";
cout << myptr << endl;

// printing value of x using pointer myptr


cout << "Value of x using *myptr is: ";
cout << *myptr << endl;

return 0;
}
OUTPUT

Value of x is: 10
Address stored in myptr is: 0x7ffd2b32c7f4
Value of x using *myptr is: 10
THANK YOU

You might also like