SlideShare a Scribd company logo
By,
A.AMALAJOYLET
5/31/2014
5/31/2014
• Introduction
• Arithmetic on a pointer
• Pointers and Functions
• Pointers and Arrays
• Arrays of Pointers
• Advanced Pointer Notation
–Contains memory address as their values.
–Normal variable contains a specific value.
–Pointers contain address of a variable.
–We can have a pointer to any variable type.
5/31/2014
• The unary or monadic operator & gives the
``address of a variable'‘
• The indirection or dereference
operator * gives the ``contents of an
object pointed to by a pointer''.
Indirection Operator *
5/31/2014
1.We must associate a pointer to a particular Data type
2.Data type of pointer variable & variable must be same
3.Help us to know How many bytes of data is stored in?
int i=1,*ip; // pointer Declaration
ip=&i;//Pointer Assignment
*ip=3;//Pointer Assignment
5/31/2014
When a pointer is declared it does not point
anywhere. You must set it to point somewhere
before you use it
5/31/2014
Pointer Arithmetic
• Operations are meaningless unless performed on an
array.
• An arithmetic operator increases and decreases its
contents by the size of the data type it points to it
• When we increment a pointer we increase pointer by
one ``block'' memory
• Call by value
– Pass the value of the variable to the
function.
x
void main()
{
int = 10;
print(x);
printf(“n%d”,x);
}
x)void print(inta
a += 10;
printf(“%d”,a);
}
10
120
20
10
• Do not pass a
variable.
• Pass address of variable using &
operator.
• Allows you to change the value directly at memory
location.
• Arrays are not passed with & because the array
name
is already a pointer.
print(x);
print(&x);
• Call by reference
– Pass the address of the variable to the
function.
x
void main()
{
int = 10;
prin(&x);
printf(“n%d”,x);
}
void prin(int *y)
{
*y += 10;
printf(“%d”,x);
}
&x
120
20
20
5/31/2014
• pa = a; instead of pa = &a[0]
• a[i] can be written as *(pa + i).
5/31/2014
• When an array is passed to a function what is
actually passed is its initial elements location in
memory
• strlen(s) strlen(&s[0])
• This is why we declare the function:
• int strlen(char s[]);
• An equivalent declaration is : int strlen(char *s);
• We can have arrays of pointers since pointers
are variables.
• Arrays can contain pointers
• For example: an array of strings
• Name array has a fixed size, but strings can be
of any size.
char *name[3] = { “rajan”, “sonu”, “hari”};
‘r’ ‘a’ ‘j’ ‘a’ ‘n’ ‘’
‘s’ ‘o’ ‘n’ ‘u’ ‘0’
‘h’ ‘a’ ‘r’ ‘i’ ‘0’
•
•
•
name[0]
name[1]
name[2]
14
• Two-dimensional numeric arrays
• int nums[2][3] = {{16,18,20},{25,26,27}};
Pointer Notation Array Notation Value
*(*nums) nums[ 0 ] [ 0 ] 16
*(*nums + 1) nums [ 0 ] [ 1 ] 18
*(*nums + 2) nums [ 0 ] [ 2 ] 20
*(*(nums + 1)) nums [ 1 ] [ 0 ] 25
*(*(nums + 1) +1) nums [ 1 ] [ 1 ] 26
*(*(nums + 1) +2) nums [ 1 ] [ 2 ] 27
5/31/2014

More Related Content

PPT
Pointers
Lp Singh
 
PPTX
Double pointer (pointer to pointer)
sangrampatil81
 
PDF
Pointers
sarith divakar
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
C pointer
University of Potsdam
 
PPTX
Pointers in c++
Rajat Busheheri
 
PPT
Pointers (Pp Tminimizer)
tech4us
 
Pointers
Lp Singh
 
Double pointer (pointer to pointer)
sangrampatil81
 
Pointers
sarith divakar
 
Pointers in c++
Vineeta Garg
 
Pointers in c++
Rajat Busheheri
 
Pointers (Pp Tminimizer)
tech4us
 

What's hot (20)

PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
PPTX
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
Pointer in C++
Mauryasuraj98
 
PPTX
C programming - Pointer and DMA
Achyut Devkota
 
PPTX
Pointers in c v5 12102017 1
tanmaymodi4
 
PPTX
This pointer
Kamal Acharya
 
PPTX
Fundamentals of Pointers in C
ShivanshuVerma11
 
PDF
Pointer in c++ part2
Subhasis Nayak
 
PPT
pointers
teach4uin
 
PPTX
Pointers in c - Mohammad Salman
MohammadSalman129
 
PDF
C Programming - Refresher - Part II
Emertxe Information Technologies Pvt Ltd
 
PPTX
C programming - Pointers
Wingston
 
PPT
C++ Pointers And References
verisan
 
PPTX
Function Pointer
Dr-Dipali Meher
 
PPTX
Pointer in c
lavanya marichamy
 
PPT
Pointers in C
Prabhu Govind
 
PPTX
Pointer in c
Imamul Kadir
 
PDF
Pointer
Learn By Watch
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Pointers in c++
sai tarlekar
 
Pointer in C++
Mauryasuraj98
 
C programming - Pointer and DMA
Achyut Devkota
 
Pointers in c v5 12102017 1
tanmaymodi4
 
This pointer
Kamal Acharya
 
Fundamentals of Pointers in C
ShivanshuVerma11
 
Pointer in c++ part2
Subhasis Nayak
 
pointers
teach4uin
 
Pointers in c - Mohammad Salman
MohammadSalman129
 
C Programming - Refresher - Part II
Emertxe Information Technologies Pvt Ltd
 
C programming - Pointers
Wingston
 
C++ Pointers And References
verisan
 
Function Pointer
Dr-Dipali Meher
 
Pointer in c
lavanya marichamy
 
Pointers in C
Prabhu Govind
 
Pointer in c
Imamul Kadir
 
Ad

Similar to Pointers (20)

PPT
Pointers C programming
Appili Vamsi Krishna
 
PPT
l7-pointers.ppt
ShivamChaturvedi67
 
PPTX
PPS-POINTERS.pptx
sajinis3
 
PPTX
20.C++Pointer.pptx
AtharvPotdar2
 
PPT
pointers (1).ppt
Osmania University
 
PPSX
Pointers
Frijo Francis
 
PPT
SPC Unit 3
SIMONTHOMAS S
 
PPT
Session 5
Shailendra Mathur
 
PPTX
Pointer
khyati thakkar
 
DOCX
08-Pointers.docx An array is a linear data structure
bhargavi804095
 
PPTX
FYBSC(CS)_UNIT-1_Pointers in C.pptx
sangeeta borde
 
PPT
Lect 9(pointers) Zaheer Abbas
Information Technology Center
 
PPT
Lect 8(pointers) Zaheer Abbas
Information Technology Center
 
PPTX
Chp3(pointers ref)
Mohd Effandi
 
PPTX
Pointers and single &multi dimentionalarrays.pptx
Ramakrishna Reddy Bijjam
 
PPTX
pointers.pptx
s170883BesiVyshnavi
 
PDF
Pointers are one of the core components of the C programming language.
bhargavi804095
 
PPTX
4 Pointers.pptx
aarockiaabinsAPIICSE
 
Pointers C programming
Appili Vamsi Krishna
 
l7-pointers.ppt
ShivamChaturvedi67
 
PPS-POINTERS.pptx
sajinis3
 
20.C++Pointer.pptx
AtharvPotdar2
 
pointers (1).ppt
Osmania University
 
Pointers
Frijo Francis
 
SPC Unit 3
SIMONTHOMAS S
 
08-Pointers.docx An array is a linear data structure
bhargavi804095
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
sangeeta borde
 
Lect 9(pointers) Zaheer Abbas
Information Technology Center
 
Lect 8(pointers) Zaheer Abbas
Information Technology Center
 
Chp3(pointers ref)
Mohd Effandi
 
Pointers and single &multi dimentionalarrays.pptx
Ramakrishna Reddy Bijjam
 
pointers.pptx
s170883BesiVyshnavi
 
Pointers are one of the core components of the C programming language.
bhargavi804095
 
4 Pointers.pptx
aarockiaabinsAPIICSE
 
Ad

Recently uploaded (20)

PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPTX
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
Zero Carbon Building Performance standard
BassemOsman1
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 

Pointers

  • 2. 5/31/2014 • Introduction • Arithmetic on a pointer • Pointers and Functions • Pointers and Arrays • Arrays of Pointers • Advanced Pointer Notation
  • 3. –Contains memory address as their values. –Normal variable contains a specific value. –Pointers contain address of a variable. –We can have a pointer to any variable type.
  • 4. 5/31/2014 • The unary or monadic operator & gives the ``address of a variable'‘ • The indirection or dereference operator * gives the ``contents of an object pointed to by a pointer''. Indirection Operator *
  • 5. 5/31/2014 1.We must associate a pointer to a particular Data type 2.Data type of pointer variable & variable must be same 3.Help us to know How many bytes of data is stored in? int i=1,*ip; // pointer Declaration ip=&i;//Pointer Assignment *ip=3;//Pointer Assignment
  • 7. When a pointer is declared it does not point anywhere. You must set it to point somewhere before you use it 5/31/2014
  • 8. Pointer Arithmetic • Operations are meaningless unless performed on an array. • An arithmetic operator increases and decreases its contents by the size of the data type it points to it • When we increment a pointer we increase pointer by one ``block'' memory
  • 9. • Call by value – Pass the value of the variable to the function. x void main() { int = 10; print(x); printf(“n%d”,x); } x)void print(inta a += 10; printf(“%d”,a); } 10 120 20 10
  • 10. • Do not pass a variable. • Pass address of variable using & operator. • Allows you to change the value directly at memory location. • Arrays are not passed with & because the array name is already a pointer. print(x); print(&x);
  • 11. • Call by reference – Pass the address of the variable to the function. x void main() { int = 10; prin(&x); printf(“n%d”,x); } void prin(int *y) { *y += 10; printf(“%d”,x); } &x 120 20 20
  • 12. 5/31/2014 • pa = a; instead of pa = &a[0] • a[i] can be written as *(pa + i).
  • 13. 5/31/2014 • When an array is passed to a function what is actually passed is its initial elements location in memory • strlen(s) strlen(&s[0]) • This is why we declare the function: • int strlen(char s[]); • An equivalent declaration is : int strlen(char *s);
  • 14. • We can have arrays of pointers since pointers are variables. • Arrays can contain pointers • For example: an array of strings • Name array has a fixed size, but strings can be of any size. char *name[3] = { “rajan”, “sonu”, “hari”}; ‘r’ ‘a’ ‘j’ ‘a’ ‘n’ ‘’ ‘s’ ‘o’ ‘n’ ‘u’ ‘0’ ‘h’ ‘a’ ‘r’ ‘i’ ‘0’ • • • name[0] name[1] name[2] 14
  • 15. • Two-dimensional numeric arrays • int nums[2][3] = {{16,18,20},{25,26,27}}; Pointer Notation Array Notation Value *(*nums) nums[ 0 ] [ 0 ] 16 *(*nums + 1) nums [ 0 ] [ 1 ] 18 *(*nums + 2) nums [ 0 ] [ 2 ] 20 *(*(nums + 1)) nums [ 1 ] [ 0 ] 25 *(*(nums + 1) +1) nums [ 1 ] [ 1 ] 26 *(*(nums + 1) +2) nums [ 1 ] [ 2 ] 27