SlideShare a Scribd company logo
1 of 16
Fundamentals of pointers
UNIT IV
By : Shivanshu Verma
Introduction to Pointers
A pointer is a variable that holds a memory address. This address is the location of
another object(typically another variable) in a memory.
Pointers notations in C
 You can use a pointer on the right-hand side of an assignment statement to
assign its value to another pointer. When both Pointers are the same type, the
situation is straightforward.
Declaration of pointer
 A pointer is declared as “data-type*pointer-variable-name”.
 * symbol specifies it is a pointer variable. You must prefix * before variable name
to declare it as a pointer.
 Pointer-variable-name is a valid C identifier i.e. the name of pointer variable.
Operations that can be performed on a computer
 Assignment
 Value finding
 Taking a pointer address
 Adding an integer to a pointer
 Incrementing a pointer
 Subtracting an integer from a pointer
 Decrementing a pointer
 Differencing
 comparision
Use of pointers in programming exercises
 Pointers are more efficient in handling arrays and structures
 Pointers are used to return multiple values from a function
 Pointer allow dynamic memory allocation and deallocation in C.
 Pointers allow to refer and pass a function as a parameter to functions
Parameters passing in pointers
 These are of two types
 Call by value
 Call by reference
Call by value
 In call by value method, the value of actual parameters is copied into the formal
parameters in other words we can say that the value of variable is used in the
function call in the call by value method.
 The actual parameters is the argument which is used in the function call whereas
formal parameter is the argument which is used in the function definition.
Call by reference
 In call by reference, the address of the variable is passed into the function call as
the actual parameters.
 The value of the actual parameters can be modified by changing the formal
parameter since the address of the actual parameter is passed.
Array and character using pointers
Dynamic Allocation
 It can be done by four methods
1. Malloc
2. Calloc
3. Realloc
4. free
Malloc
 It stores data in a one memory chunk
 It does not initializes memory at 0
 When memory is insufficient it points at NULL value
 Syntax: <pointer_name>=(cast type *)malloc(size)
Calloc
 It creates multiple block of memory
 It points at NULL value if memory is insufficient
 It initializes memory at 0
 Suntax : <pointer_name>=(cast_type *)calloc(n,size)
Realloc
 It is used to increase or decrease the size of memory. Basically used after malloc or
calloc
 Syntax: <pointer_name>=realloc(ptr_name,new size)
Free
Put it at the place(usually end of program) to remove the memory of at pointer
Syntax: free(pointer_name)
Thank You

More Related Content

What's hot (20)

C Pointers
C PointersC Pointers
C Pointers
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Arrays
ArraysArrays
Arrays
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
pointers
pointerspointers
pointers
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypes
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Array ppt
Array pptArray ppt
Array ppt
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 

Similar to Fundamentals of Pointers in C

Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C languageMehwish Mehmood
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming conceptsandeshjadhav28
 
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
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
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
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageHariTharshiniBscIT1
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphismlalithambiga kamaraj
 
cprogrammingpointerstype.ppt
cprogrammingpointerstype.pptcprogrammingpointerstype.ppt
cprogrammingpointerstype.pptakila m
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 

Similar to Fundamentals of Pointers in C (20)

Pointers
PointersPointers
Pointers
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 
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
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
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
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming language
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Pointers
PointersPointers
Pointers
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
cprogrammingpointerstype.ppt
cprogrammingpointerstype.pptcprogrammingpointerstype.ppt
cprogrammingpointerstype.ppt
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 

Fundamentals of Pointers in C

  • 1. Fundamentals of pointers UNIT IV By : Shivanshu Verma
  • 2. Introduction to Pointers A pointer is a variable that holds a memory address. This address is the location of another object(typically another variable) in a memory.
  • 3. Pointers notations in C  You can use a pointer on the right-hand side of an assignment statement to assign its value to another pointer. When both Pointers are the same type, the situation is straightforward.
  • 4. Declaration of pointer  A pointer is declared as “data-type*pointer-variable-name”.  * symbol specifies it is a pointer variable. You must prefix * before variable name to declare it as a pointer.  Pointer-variable-name is a valid C identifier i.e. the name of pointer variable.
  • 5. Operations that can be performed on a computer  Assignment  Value finding  Taking a pointer address  Adding an integer to a pointer  Incrementing a pointer  Subtracting an integer from a pointer  Decrementing a pointer  Differencing  comparision
  • 6. Use of pointers in programming exercises  Pointers are more efficient in handling arrays and structures  Pointers are used to return multiple values from a function  Pointer allow dynamic memory allocation and deallocation in C.  Pointers allow to refer and pass a function as a parameter to functions
  • 7. Parameters passing in pointers  These are of two types  Call by value  Call by reference
  • 8. Call by value  In call by value method, the value of actual parameters is copied into the formal parameters in other words we can say that the value of variable is used in the function call in the call by value method.  The actual parameters is the argument which is used in the function call whereas formal parameter is the argument which is used in the function definition.
  • 9. Call by reference  In call by reference, the address of the variable is passed into the function call as the actual parameters.  The value of the actual parameters can be modified by changing the formal parameter since the address of the actual parameter is passed.
  • 10. Array and character using pointers
  • 11. Dynamic Allocation  It can be done by four methods 1. Malloc 2. Calloc 3. Realloc 4. free
  • 12. Malloc  It stores data in a one memory chunk  It does not initializes memory at 0  When memory is insufficient it points at NULL value  Syntax: <pointer_name>=(cast type *)malloc(size)
  • 13. Calloc  It creates multiple block of memory  It points at NULL value if memory is insufficient  It initializes memory at 0  Suntax : <pointer_name>=(cast_type *)calloc(n,size)
  • 14. Realloc  It is used to increase or decrease the size of memory. Basically used after malloc or calloc  Syntax: <pointer_name>=realloc(ptr_name,new size)
  • 15. Free Put it at the place(usually end of program) to remove the memory of at pointer Syntax: free(pointer_name)