Professional Documents
Culture Documents
Pointer-in-C 8803017 Powerpoint
Pointer-in-C 8803017 Powerpoint
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;
… 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)