SlideShare a Scribd company logo
1 of 16
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

What's hot (20)

Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
This pointer
This pointerThis pointer
This pointer
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
pointers
pointerspointers
pointers
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointer
PointerPointer
Pointer
 

Similar to Pointers (20)

Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
 
Pointer
PointerPointer
Pointer
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
Pointers
PointersPointers
Pointers
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
 
Session 5
Session 5Session 5
Session 5
 
Pointer
PointerPointer
Pointer
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 

Recently uploaded

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 

Recently uploaded (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 

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