SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
verisan
 

La actualidad más candente (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 a Pointers

Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
Mohd Effandi
 

Similar a 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
 

Último

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 

Último (20)

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
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
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
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.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
 

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