Escolar Documentos
Profissional Documentos
Cultura Documentos
ANDHRA PRADESH
Name : Murali Krishna Chintala
Designation : Lecturer in CME
Branch : Computer Engineering
Institute : SUVR & SR GPW, Ethamukkala
Year/Semester : III Semester
Subject : UNIX & C
Subject Code : CM – 304
Topic : Basics of Pointers
Duration : 50 Min
Sub Topic : Address and De-referencing operators
Teaching Aids : PPT, Animations
CM304.69 1
Objective
CM304.69 2
Recap
• Recursion
CM304.69 3
How to store variables in memory?
CM304.69 4
Pointer definition
The address of a data item is called a pointer to the
data item.
CM304.69 5
Pointer
1020 y 1000 x
Value
1000 10 of x
Address of x
CM304.69 6
Pointer
Example
y x
1000 10
1020 1000
CM304.69 7
Uses of Pointers
CM304.69 8
Uses of Pointers
Contd..
CM304.69 9
Uses of Pointers
Contd..
CM304.69 10
Address & De-referencing operators
x
int x=10; 10
p
Garbage address
int *p ;
y
Garbage values
int y;
CM304.69 11
Contd..
Address & De-referencing operators
p=&x p=&x
1020 p 1000 x 1020 p 1000 x
1000 10 1000 10
y=*p;
y
10
CM304.69 12
Address and De-referencing operators
CM304.69 13
Address and De-referencing operators
Contd..
‘&’ is read as “address off”.
Example:
a=&count;
CM304.69 14
Address and De-referencing operators
CM304.69 15
Usage Of Address Operator
Example:
#include<stdio.h>
main()
{
int x=100;
printf(“address of x is %u”,&x);
}
Note:
Since addresses are unsigned integers %u is used.
Output:- Address of the variable x is printed
CM304.69 16
Usage of De-referencing operator
Example:
#include<stdio.h>
main()
{
int x=100;
printf(“address of x is %u”,&x);
printf(“value of x is &d”,x);
printf(“value of x is %u”,*(&x));
}
CM304.69 17
Usage of De-referencing operator Contd..
Output:
Address of x is 324518943
value of x is 100
value of x is 100
&x gives the address of the variable x
CM304.69 18
Differences between addressing and
De-referencing operators
Address operator De-referencing operator
CM304.69 19
Differences between addressing and
De-referencing operators
Address operator De-referencing operator
CM304.69 20
Summary
CM304.69 21
Quiz
1.Variable which holds the address of another
variable is
a. function
b. pointer
c. array
CM304.69 22
Quiz
1.Variable which holds the address of another
variable is
a. function
b. pointer
c. array
CM304.69 23
Quiz
CM304.69 24
Quiz
CM304.69 25
Quiz
a) Unary operators
b) Arithmetic operators
c) Logical operators
CM304.69 26
Quiz
a) Unary operators
b) Arithmetic operators
c) Logical operators
CM304.69 27
Frequently Asked Questions
CM304.69 28