SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
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

PPTX
PPTX
Pointers in c language
PPTX
POINTERS IN C
PPTX
Pointer in c program
PPTX
Pointers in c++
PPTX
Pointer in c
PPTX
Presentation on pointer.
PPTX
Pointers in c - Mohammad Salman
Pointers in c language
POINTERS IN C
Pointer in c program
Pointers in c++
Pointer in c
Presentation on pointer.
Pointers in c - Mohammad Salman

What's hot (20)

PPTX
Pointers in C Programming
PDF
C Pointers
PPTX
Pointer in C
PDF
Pointers in C
PPTX
Pointers in C
PPTX
Pointer in C++
PPTX
Array Of Pointers
PPT
Structures
PPTX
Pointers in C Language
PPTX
Pointer arithmetic in c
PDF
Types of pointer in C
PPTX
Pointers in c
PDF
Pointers
PPTX
C programming - String
PPTX
Pointers and Structures.pptx
PPTX
Union in C programming
PPTX
Pointers in c++
PPTX
C programing -Structure
PPTX
C programming - Pointers
PPT
Pointers C programming
Pointers in C Programming
C Pointers
Pointer in C
Pointers in C
Pointers in C
Pointer in C++
Array Of Pointers
Structures
Pointers in C Language
Pointer arithmetic in c
Types of pointer in C
Pointers in c
Pointers
C programming - String
Pointers and Structures.pptx
Union in C programming
Pointers in c++
C programing -Structure
C programming - Pointers
Pointers C programming
Ad

Similar to Fundamentals of Pointers in C (20)

PPTX
Pointer in C and its significance, Relationship between pointers and memory a...
PPTX
POINTERS in C language:- Mastering-Pointers-in-C
PPT
pointers (1).ppt
PDF
C++ Pointers , Basic to advanced Concept
PDF
PROBLEM SOLVING USING PPSC- UNIT -4.pdf
PPTX
pointers in c programming - example programs
PPTX
Advance topics of C language
PPTX
2-Concept of Pointers in c programming.pptx
DOCX
Dot net programming concept
PPTX
Pointers_in_c_2024.01.10_embedded _c.pptx
PPTX
Programming in C sesion 2
PPTX
pointers.pptx
PPTX
Structured Languages
PPTX
Chp3(pointers ref)
PDF
Pointers-Computer programming
PPTX
FYBSC(CS)_UNIT-1_Pointers in C.pptx
PPTX
C++ Class & object pointer in c++ programming language
PPTX
Pointer.pptx
PPT
cprogrammingpointerstype.ppt Pointers are used to store and manage the addres...
Pointer in C and its significance, Relationship between pointers and memory a...
POINTERS in C language:- Mastering-Pointers-in-C
pointers (1).ppt
C++ Pointers , Basic to advanced Concept
PROBLEM SOLVING USING PPSC- UNIT -4.pdf
pointers in c programming - example programs
Advance topics of C language
2-Concept of Pointers in c programming.pptx
Dot net programming concept
Pointers_in_c_2024.01.10_embedded _c.pptx
Programming in C sesion 2
pointers.pptx
Structured Languages
Chp3(pointers ref)
Pointers-Computer programming
FYBSC(CS)_UNIT-1_Pointers in C.pptx
C++ Class & object pointer in c++ programming language
Pointer.pptx
cprogrammingpointerstype.ppt Pointers are used to store and manage the addres...
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Structure & Organelles in detailed.
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Anesthesia in Laparoscopic Surgery in India
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Sports Quiz easy sports quiz sports quiz
Microbial disease of the cardiovascular and lymphatic systems
Module 4: Burden of Disease Tutorial Slides S2 2025
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
RMMM.pdf make it easy to upload and study
Cell Structure & Organelles in detailed.
GDM (1) (1).pptx small presentation for students
Abdominal Access Techniques with Prof. Dr. R K Mishra

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)