SlideShare a Scribd company logo
Author – Subhasis Nayak
   Pointer assignments
   Pointer arithmetic
   Pointer comparisons
   Pointers & arrays
   Arrays of pointers
   Multiple indirection
   Pointers to function
   Dynamic allocations
   We know how to point a variable .
      In this example I will show how to point a
       variable from two pointers.

You must pass the vaddres1
to vAddress2.Because we
passed the address of
variable to vaddress1 not to
vAddress2
   There are only two arithmetic operations that
    you may use on pointers:
    ◦ Addition
    ◦ Subtraction
   But you can do all operation on pointer’s
    value as:
    ◦   Addition
    ◦   Subtraction
    ◦   Multiplication
    ◦   division
   There are two type of comparison of pointers
    ◦ In between pointer = this is the comparison held
      between the addresses they hold

                      If (p1>p2)


    ◦ In between pointer value = here we comparing
      between the values they hold.

                     If (*p1>*p2)
Pointer in c++ part2
Pointer in c++ part2
   you can direct a pointer to hold the array's address as
    we do for a normal variable.
   As I told you array is a sequence of similar type of
    data type.
   To hold the array's address when you direct the
    pointer to hold array's address it holds the first’s of
    that array address only.
   To get the address of each element of array we have
    to add the exact index number of that element. how
    can we do that? we can do that with help of a loop or
    directly adding the index’s number.
Int array[5];     Int array[5];
Int *Parray;      Int *Parray;
Parray = array;   Parray = &array[0];
Pointer in c++ part2
Pointer in c++ part2
Pointer in c++ part2
   We already learned array of integers, array of
    floats. As like those we have one type of array i.e.
    Arrays of pointer.
   Arrays of pointer will only hold a bunch of
    addresses.
   These addresses may be addresses of arrays or
    may be addresses of different variables.
   As for a integer type array compiler allocates
    sequence of memory to store hold addresses.
   When we create pointer array we have to
    initialize the each element to direct to a
    address.
   The address may be a address of a variable or
    an array. But they must be similar data type
    of pointer array
                    int var1 = 400,var2 = 600;

                    int *arrpo[2];

                    arrpo[0] = &var1;
                    arrpo[1] = &var2;
Pointer in c++ part2
Pointer in c++ part2
   We can say it point to pointer. It means we can
    hold the address of a pointer as we hold the
    address of the variable.
   So when a pointer points to the address of a
    variable we told it indirection. When another
    pointer points to that pointer which points to a
    variable is called multiple indirection.

                     int var;
                     int *fPointer,**spointer;
                     fpointer = &var;
                     spointer = &fpointer;
Pointer02     Pointer01     variable

  • Address     • Address     • Value
   When we have a pointer to a pointer the
    pointer which will point to variable. We will
    confuse with (*), (**) and (&). So do not
    confuse with these.
                                 var = gives value stored in var
    int var;                    *fpointer = gives value stored in var
    int *fPointer,**spointer;   **spointer = gives value stored in var
    fpointer = &var;
    spointer = &fpointer;
                                *spointer = gives address of fpointer
                                &spointer = gives address of spointer
                                &fpointer = gives address of fpointer
                                &var = gives address of variable
Pointer in c++ part2
   Even though a function is not a variable, it still
    has a physical location in memory that can be
    assigned to a pointer.
   This address is the entry point of the function
    and it is the address used when the function is
    called.
   Once a pointer points to a function, the function
    can be called through that pointer.
   Function pointers also allow functions to be
    passed as arguments to other functions.

More Related Content

PPTX
Pointers in c++
PDF
Pointers
PPT
Pointers (Pp Tminimizer)
PPTX
Pointers in c++
PPT
C++ Pointers And References
PPT
Pointers in c
PPTX
Pointers in c++
PPTX
Pointer in c program
Pointers in c++
Pointers
Pointers (Pp Tminimizer)
Pointers in c++
C++ Pointers And References
Pointers in c
Pointers in c++
Pointer in c program

What's hot (20)

ODP
Pointers in c++ by minal
PDF
Pointer in c++ part3
PPTX
c++ pointers by Amir Hamza Khan (SZABISTIAN)
PDF
Pointer in c++ part1
PPTX
PPTX
Pointer in C++
PPTX
C programming - Pointer and DMA
PPTX
C programming - Pointers
PPT
pointers
PPT
PDF
PDF
C Pointers
PPTX
Pointer in c
PPTX
Pointers in c v5 12102017 1
PPTX
Pointers
PPT
Pointers in C
PPT
Introduction to pointers and memory management in C
PPT
PPT
Pointers C programming
Pointers in c++ by minal
Pointer in c++ part3
c++ pointers by Amir Hamza Khan (SZABISTIAN)
Pointer in c++ part1
Pointer in C++
C programming - Pointer and DMA
C programming - Pointers
pointers
C Pointers
Pointer in c
Pointers in c v5 12102017 1
Pointers
Pointers in C
Introduction to pointers and memory management in C
Pointers C programming
Ad

Viewers also liked (10)

PPTX
Basic array in c programming
PDF
Arrays in C
PDF
Amazon Web Services
PPTX
jal hi jivan hai pre prentation
PPTX
One dimensional arrays
PPT
Structures
PPTX
Array in C
PPTX
Array in c language
PPT
PPT
Object Oriented Programming Concepts
Basic array in c programming
Arrays in C
Amazon Web Services
jal hi jivan hai pre prentation
One dimensional arrays
Structures
Array in C
Array in c language
Object Oriented Programming Concepts
Ad

Similar to Pointer in c++ part2 (20)

PDF
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
PPT
Lect 9(pointers) Zaheer Abbas
PPT
Lect 8(pointers) Zaheer Abbas
PPTX
Pointers in c language
PDF
Pointers in C
PDF
Pointers-Computer programming
PDF
PSPC--UNIT-5.pdf
PPT
Pointer introduction day1
PPTX
Pointer in c
PPTX
Pointer in c
PDF
Pointers
PPTX
13 - opp presentation Pointer to 2d arrays and DMA.pptx
PPTX
PPS-POINTERS.pptx
PPT
SPC Unit 3
PPTX
Data structure lecture 1
PPTX
20.C++Pointer.pptx
PPTX
pointers.pptx
PPTX
Presentation on pointer.
PPTX
Lecture 7_Pointer.pptx FOR EDUCATIONAL PURPOSE
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
Lect 9(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
Pointers in c language
Pointers in C
Pointers-Computer programming
PSPC--UNIT-5.pdf
Pointer introduction day1
Pointer in c
Pointer in c
Pointers
13 - opp presentation Pointer to 2d arrays and DMA.pptx
PPS-POINTERS.pptx
SPC Unit 3
Data structure lecture 1
20.C++Pointer.pptx
pointers.pptx
Presentation on pointer.
Lecture 7_Pointer.pptx FOR EDUCATIONAL PURPOSE

More from Subhasis Nayak (18)

PDF
Php, mysq lpart5(mysql)
PDF
working with database using mysql
PDF
Php, mysq lpart3
PDF
Php, mysq lpart4(processing html form)
PPT
PPT
Jsp 02(jsp directives)2003
PPT
Php, mysq lpart1
PPT
Php, mysqlpart2
PPTX
C:\fakepath\jsp01
PPTX
Servlet & jsp
PPT
J2ee connector architecture
PPT
how to create object
PDF
C++ arrays part2
ODP
C++ arrays part1
PDF
Introduction to network
PDF
Flow control in c++
PPT
Oops And C++ Fundamentals
PPT
Text mode Linux Installation Part 01
Php, mysq lpart5(mysql)
working with database using mysql
Php, mysq lpart3
Php, mysq lpart4(processing html form)
Jsp 02(jsp directives)2003
Php, mysq lpart1
Php, mysqlpart2
C:\fakepath\jsp01
Servlet & jsp
J2ee connector architecture
how to create object
C++ arrays part2
C++ arrays part1
Introduction to network
Flow control in c++
Oops And C++ Fundamentals
Text mode Linux Installation Part 01

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Pharma ospi slides which help in ospi learning
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Trump Administration's workforce development strategy
PPTX
Cell Types and Its function , kingdom of life
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Structure & Organelles in detailed.
Yogi Goddess Pres Conference Studio Updates
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Weekly quiz Compilation Jan -July 25.pdf
Final Presentation General Medicine 03-08-2024.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Pharma ospi slides which help in ospi learning
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
GDM (1) (1).pptx small presentation for students
Trump Administration's workforce development strategy
Cell Types and Its function , kingdom of life
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf

Pointer in c++ part2

  • 2. Pointer assignments  Pointer arithmetic  Pointer comparisons  Pointers & arrays  Arrays of pointers  Multiple indirection  Pointers to function  Dynamic allocations
  • 3. We know how to point a variable .  In this example I will show how to point a variable from two pointers. You must pass the vaddres1 to vAddress2.Because we passed the address of variable to vaddress1 not to vAddress2
  • 4. There are only two arithmetic operations that you may use on pointers: ◦ Addition ◦ Subtraction  But you can do all operation on pointer’s value as: ◦ Addition ◦ Subtraction ◦ Multiplication ◦ division
  • 5. There are two type of comparison of pointers ◦ In between pointer = this is the comparison held between the addresses they hold If (p1>p2) ◦ In between pointer value = here we comparing between the values they hold. If (*p1>*p2)
  • 8. you can direct a pointer to hold the array's address as we do for a normal variable.  As I told you array is a sequence of similar type of data type.  To hold the array's address when you direct the pointer to hold array's address it holds the first’s of that array address only.  To get the address of each element of array we have to add the exact index number of that element. how can we do that? we can do that with help of a loop or directly adding the index’s number.
  • 9. Int array[5]; Int array[5]; Int *Parray; Int *Parray; Parray = array; Parray = &array[0];
  • 13. We already learned array of integers, array of floats. As like those we have one type of array i.e. Arrays of pointer.  Arrays of pointer will only hold a bunch of addresses.  These addresses may be addresses of arrays or may be addresses of different variables.  As for a integer type array compiler allocates sequence of memory to store hold addresses.
  • 14. When we create pointer array we have to initialize the each element to direct to a address.  The address may be a address of a variable or an array. But they must be similar data type of pointer array int var1 = 400,var2 = 600; int *arrpo[2]; arrpo[0] = &var1; arrpo[1] = &var2;
  • 17. We can say it point to pointer. It means we can hold the address of a pointer as we hold the address of the variable.  So when a pointer points to the address of a variable we told it indirection. When another pointer points to that pointer which points to a variable is called multiple indirection. int var; int *fPointer,**spointer; fpointer = &var; spointer = &fpointer;
  • 18. Pointer02 Pointer01 variable • Address • Address • Value
  • 19. When we have a pointer to a pointer the pointer which will point to variable. We will confuse with (*), (**) and (&). So do not confuse with these.  var = gives value stored in var int var; *fpointer = gives value stored in var int *fPointer,**spointer; **spointer = gives value stored in var fpointer = &var; spointer = &fpointer; *spointer = gives address of fpointer &spointer = gives address of spointer &fpointer = gives address of fpointer &var = gives address of variable
  • 21. Even though a function is not a variable, it still has a physical location in memory that can be assigned to a pointer.  This address is the entry point of the function and it is the address used when the function is called.  Once a pointer points to a function, the function can be called through that pointer.  Function pointers also allow functions to be passed as arguments to other functions.