SlideShare a Scribd company logo
1 of 26
POINTERS
Presented by
Er. Jasleen Kaur
Assistant Professor
Applied Science(CSE)
Chandigarh University
Gharuan (Mohali).
Pointer
• A variable that holds a memory address.
• This address is the location of another object
in the memory.
• Pointer as an address indicates where to find
an object.
Not all pointers actually contain an address
example NULL pointer.
Value of NULL pointer is 0.
10/19/2015
• Pointer can have three kinds of content in it
1) The address of an object, which can be
dereferenced.
2) A NULL pointer.
3) Invalid content, which does not point to an
object.
(If p does not hold a valid value, it can crash the
program)
• If p is a pointer to integer, then
– Int *p
It is possible in some environments to have
multiple pointer values with different
representations that point to same location in
memory.
But make sure if the memory is deleted using
delete or if original variable goes out of scope.
Declaring pointer
Data-type *name;
* is a unary operator, also called as indirection
operator.
Data-type is the type of object which the
pointer is pointing.
Any type of pointer can point to anywhere in
the memory.
* is used to declare a pointer and also to
dereference a pointer.
When you write int *,
compiler assumes that any address that it
holds points to an integer type.
 m= &count;
it means memory address of count variable is
stored into m.
& is unary operator that returns the memory
address.
i.e. & (orally called as ampersand) is returning
the address.
 so it means m receives the address of count.
Suppose, count uses memory
Address 2000 to store its value 100.
so, m=&count means m has 2000
address.
q= *m
it returns the value at address m.
value at address 2000 is 100.
so, q will return value 100.
i.e. q receives the value at address m.
count=1002000
Address-of operator(&)
• It is used to reference the memory address of
a variable.
• When we declare a variable, 3 things happen
– Computer memory is set aside for variable
– Variable name is linked to that location in memory
– Value of variable is placed into the memory that
was set aside.
Int *ptr;
declaring variable ptr which holds the value
at address of int type
 int val =1;
assigning int the literal value of 1
 ptr=&val;
dereference and get value at address stored in
ptr
int deref =*ptr
printf(“%dn”, deref);
Output will be 1
Pointer Conversions
• One type of pointer can be converted to
another type of pointer.
• int main() {
double x=100.1, y;
int *p;
p= (int *) &x; //explicit type conversion
y= *p;
}
Generic Pointer
void * pointer is called as generic pointer.
Can’t convert void *pointer to another pointer
and vice-versa.
void *pointer can be assigned to any other
type of pointer.
void * is used to specify a pointer whose base
type is unknown.
It is capable of receiving any type of pointer
argument without reporting any type of
mismatch.
Pointer Arithmetic
• There are only two arithmetic operations that
can be used on pointers
– Addition
– Subtraction
• To understand this concept, lets p1 be an
integer pointer with value 2000 address.
– int is of 2 bytes
– After expression p1++;
– P1 contains address 2002 not 2001.
• Each time p1 is incremented, it will point to
next integer.
• The same is true for decrement.
– for p1--;
– Causes value of p1 to be 1998.
• Each time a pointer is incremented, it points
to the memory location of the next element of
its base type.
• If decremented, then it points to previous
element location.
• P1=p1+12; makes p1 points to 12th element of
p1 type.
Arithmetic Rules
• You cannot multiply or divide pointers.
• You cannot add or subtract two pointers.
• You cannot apply bitwise operators to them.
• You cannot add or subtract type float or
double to or from pointers.
Pointer Comparison
• You can compare two pointers in a relational
expression, example:
if(p<q)
printf(“p points to lower memory than q n”);
• Pointer comparison are useful only when two
pointers point to a common object such as an
array.
Benefits of pointer
• Pointers are used in situations when passing actual values is
difficult or not desired.
• To return more than one value from a function.
• They increase the execution speed.
• The pointer are more efficient in handling the data types .
• Pointers reduce the length and complexity of a program.
• The use of a pointer array to character string results in
saving of data.
• To allocate memory and access it( Dynamic memory
Allocation).
• Implementing linked lists, trees graphs and many other data
structure.
How to get address of a function
/*A program to get address of a function */
#include<stdio.h>
void main()
{
void show(); /* usual way of invoking a function */
printf(“ The address of show function is=%u”, show);
}
void show()
{
printf(“ welcome to HPES!!”)
}
Uses of pointer to function
• Pointers are certainly awkward and off-putting and thus
this feature of pointer is used for invoking a function
• There are several possible uses :
(a) In writing memory resident program.
(b) In writing viruses, or vaccines to
remove the viruses.
(c) In developing COM/DCOM component
(d) In VC++ programming to connect events to
function calls.
10/19/2015
10/19/2015
10/19/2015
10/19/2015
10/19/2015
10/19/2015
10/19/2015
Thank you

More Related Content

What's hot

What's hot (20)

RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Structure in C
Structure in CStructure in C
Structure in C
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
C functions
C functionsC functions
C functions
 
C Pointers
C PointersC Pointers
C Pointers
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Array in c
Array in cArray in c
Array in c
 

Similar to Pointers in C Programming

Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxAnanthi Palanisamy
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)Mohd Effandi
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
 
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.pptxsangeeta borde
 
Pointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxPointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxahmedbadr608094
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
Pointers in C PPT | Poinetrs | Pointers Concept
Pointers in C PPT | Poinetrs | Pointers ConceptPointers in C PPT | Poinetrs | Pointers Concept
Pointers in C PPT | Poinetrs | Pointers Conceptsankalpkumarsahoo174
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfTamiratDejene1
 

Similar to Pointers in C Programming (20)

Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptx
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
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
 
Pointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxPointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptx
 
Lab 3.pptx
Lab 3.pptxLab 3.pptx
Lab 3.pptx
 
Lab 3.pptx
Lab 3.pptxLab 3.pptx
Lab 3.pptx
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
Pointers
PointersPointers
Pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers in C PPT | Poinetrs | Pointers Concept
Pointers in C PPT | Poinetrs | Pointers ConceptPointers in C PPT | Poinetrs | Pointers Concept
Pointers in C PPT | Poinetrs | Pointers Concept
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdf
 

More from Jasleen Kaur (Chandigarh University)

Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Jasleen Kaur (Chandigarh University)
 

More from Jasleen Kaur (Chandigarh University) (19)

Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Static variables
Static variablesStatic variables
Static variables
 
Operating system notes pdf
Operating system notes pdfOperating system notes pdf
Operating system notes pdf
 
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Remote desktop connection
Remote desktop connectionRemote desktop connection
Remote desktop connection
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Calculating garbage value in case of overflow
Calculating garbage value in case of overflowCalculating garbage value in case of overflow
Calculating garbage value in case of overflow
 
Final jasleen ppt
Final jasleen pptFinal jasleen ppt
Final jasleen ppt
 
License Plate recognition
License Plate recognitionLicense Plate recognition
License Plate recognition
 
The solar system
The solar system The solar system
The solar system
 
The solar system
The solar systemThe solar system
The solar system
 
Afforestation environmental issue
Afforestation environmental issueAfforestation environmental issue
Afforestation environmental issue
 
Data aggregation in wireless sensor networks
Data aggregation in wireless sensor networksData aggregation in wireless sensor networks
Data aggregation in wireless sensor networks
 
Network security
Network securityNetwork security
Network security
 

Recently uploaded

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 Conduitsrknatarajan
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
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 projectTonystark477637
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
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
 
(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...ranjana rawat
 
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
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
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
 
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...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 

Recently uploaded (20)

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
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
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
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
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...
 
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
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
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
 
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...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 

Pointers in C Programming

  • 1. POINTERS Presented by Er. Jasleen Kaur Assistant Professor Applied Science(CSE) Chandigarh University Gharuan (Mohali).
  • 2. Pointer • A variable that holds a memory address. • This address is the location of another object in the memory. • Pointer as an address indicates where to find an object. Not all pointers actually contain an address example NULL pointer. Value of NULL pointer is 0. 10/19/2015
  • 3. • Pointer can have three kinds of content in it 1) The address of an object, which can be dereferenced. 2) A NULL pointer. 3) Invalid content, which does not point to an object. (If p does not hold a valid value, it can crash the program) • If p is a pointer to integer, then – Int *p
  • 4. It is possible in some environments to have multiple pointer values with different representations that point to same location in memory. But make sure if the memory is deleted using delete or if original variable goes out of scope.
  • 5. Declaring pointer Data-type *name; * is a unary operator, also called as indirection operator. Data-type is the type of object which the pointer is pointing. Any type of pointer can point to anywhere in the memory. * is used to declare a pointer and also to dereference a pointer.
  • 6. When you write int *, compiler assumes that any address that it holds points to an integer type.  m= &count; it means memory address of count variable is stored into m. & is unary operator that returns the memory address. i.e. & (orally called as ampersand) is returning the address.  so it means m receives the address of count.
  • 7. Suppose, count uses memory Address 2000 to store its value 100. so, m=&count means m has 2000 address. q= *m it returns the value at address m. value at address 2000 is 100. so, q will return value 100. i.e. q receives the value at address m. count=1002000
  • 8. Address-of operator(&) • It is used to reference the memory address of a variable. • When we declare a variable, 3 things happen – Computer memory is set aside for variable – Variable name is linked to that location in memory – Value of variable is placed into the memory that was set aside.
  • 9. Int *ptr; declaring variable ptr which holds the value at address of int type  int val =1; assigning int the literal value of 1  ptr=&val; dereference and get value at address stored in ptr int deref =*ptr printf(“%dn”, deref); Output will be 1
  • 10. Pointer Conversions • One type of pointer can be converted to another type of pointer. • int main() { double x=100.1, y; int *p; p= (int *) &x; //explicit type conversion y= *p; }
  • 11. Generic Pointer void * pointer is called as generic pointer. Can’t convert void *pointer to another pointer and vice-versa. void *pointer can be assigned to any other type of pointer. void * is used to specify a pointer whose base type is unknown. It is capable of receiving any type of pointer argument without reporting any type of mismatch.
  • 12. Pointer Arithmetic • There are only two arithmetic operations that can be used on pointers – Addition – Subtraction • To understand this concept, lets p1 be an integer pointer with value 2000 address. – int is of 2 bytes – After expression p1++; – P1 contains address 2002 not 2001.
  • 13. • Each time p1 is incremented, it will point to next integer. • The same is true for decrement. – for p1--; – Causes value of p1 to be 1998. • Each time a pointer is incremented, it points to the memory location of the next element of its base type. • If decremented, then it points to previous element location. • P1=p1+12; makes p1 points to 12th element of p1 type.
  • 14. Arithmetic Rules • You cannot multiply or divide pointers. • You cannot add or subtract two pointers. • You cannot apply bitwise operators to them. • You cannot add or subtract type float or double to or from pointers.
  • 15. Pointer Comparison • You can compare two pointers in a relational expression, example: if(p<q) printf(“p points to lower memory than q n”); • Pointer comparison are useful only when two pointers point to a common object such as an array.
  • 16. Benefits of pointer • Pointers are used in situations when passing actual values is difficult or not desired. • To return more than one value from a function. • They increase the execution speed. • The pointer are more efficient in handling the data types . • Pointers reduce the length and complexity of a program.
  • 17. • The use of a pointer array to character string results in saving of data. • To allocate memory and access it( Dynamic memory Allocation). • Implementing linked lists, trees graphs and many other data structure.
  • 18. How to get address of a function /*A program to get address of a function */ #include<stdio.h> void main() { void show(); /* usual way of invoking a function */ printf(“ The address of show function is=%u”, show); } void show() { printf(“ welcome to HPES!!”) }
  • 19. Uses of pointer to function • Pointers are certainly awkward and off-putting and thus this feature of pointer is used for invoking a function • There are several possible uses : (a) In writing memory resident program. (b) In writing viruses, or vaccines to remove the viruses. (c) In developing COM/DCOM component (d) In VC++ programming to connect events to function calls.