Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

POINTERS IN

C++

POINTERS IN
C++
Present by -
Suraj R. Maurya
Topics :
All About Pointers :
Definition
Declaring Pointer Variable
&(‘Address of’ Operator)
*(‘Value of’ or Indirection Operator)
Pointers Type
Pointer Arithmetic
 Pass by Pointer in function
 Array of Pointer
String of Pointer
Object of Pointer
this Pointer
Advantages of Pointer
Limitations of Pointer
Computer Memory
• Each variable is assigned a memory slot (the
size depends on the data type) and the
variable’s data is stored there
• Eg: int a=100;

Memory address: 1020 1024 1032

… 100 … 1024 …
A
Variable a’s value, i.e., 100, is
stored at memory location 1024
• Every byte in computer memory has an
address.
• Addresses are numbers just like house
numbers.
• Addresses start from 0 and go up as 1, 2,
3….e.g. in 640 KB memory addresses will
be 0 to 655359 I.e., (640 X 1024)-1.
• The moment a variable is declared,
memory is allocated in the RAM for its
storage. int X=100;.
• A variable in the RAM can be accessed
only if you know its address.
Definition:
 A pointer is a variable which store the
memory address of another variable.
 It supports dynamic memory allocation
routines.
 A pointer variable and normal variable is
always same data type.
Declaration And Initialization Of
Pointer Variable

• Syntax :
• Datatype *variable_name;
• eg. int *x; float *y; char *z;

• Address of operator(&)- it is
a unary operator that returns the
memory address of its operand.
Here the operand is a normal
variable.
• Ptr_name=&variable_name;
• eg. int x = 10;
int *ptr ;
ptr= &x;
• Now ptr will contain address
where the variable x is stored x
in memory 10

0x5f0fff2

ptr
Address
of x
“*”(‘Value of’ or Indirection Operator)

 It is a unary operator that returns the value stored at


the address pointed to by the pointer.
 Here the operand is a pointer variable.
• eg.
• int x = 10;
• int *ptr = &x;
• cout<< ptr;// address stored at ptr will be displayed
• cout<<*ptr;// value pointed to by ptr will be
displayed
• Now ptr can also be used to change/display the value
of x.
Interesting, right?
This is just a sneak preview of the full presentation. We hope you like
it! To see the rest of it, just
click here to view it in full on PowerShow.com. Then, if you’d like, you
can also log in to PowerShow.com to download the entire
presentation for free.

You might also like