SlideShare una empresa de Scribd logo
1 de 21
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)
   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];
   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;
   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
   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.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
Pointer in c++ part3
Pointer in c++ part3Pointer in c++ part3
Pointer in c++ part3
 
c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
C pointer
C pointerC pointer
C pointer
 
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
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
pointers
pointerspointers
pointers
 
Ponters
PontersPonters
Ponters
 
Pointer
PointerPointer
Pointer
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C Pointers
C PointersC Pointers
C Pointers
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Pointers
PointersPointers
Pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 

Destacado (10)

Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Amazon Web Services
Amazon Web ServicesAmazon Web Services
Amazon Web Services
 
jal hi jivan hai pre prentation
jal hi jivan hai pre prentationjal hi jivan hai pre prentation
jal hi jivan hai pre prentation
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Structures
StructuresStructures
Structures
 
Array in C
Array in CArray in C
Array in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar a Pointer in c++ part2

Similar a Pointer in c++ part2 (20)

POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
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
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Pointer
PointerPointer
Pointer
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Pointer introduction day1
Pointer introduction day1Pointer introduction day1
Pointer introduction day1
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointer in c
Pointer in c Pointer in c
Pointer in c
 
Pointers
PointersPointers
Pointers
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on 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
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
 

Más de Subhasis Nayak

Más de Subhasis Nayak (18)

Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php, mysqlpart2
Php, mysqlpart2Php, mysqlpart2
Php, mysqlpart2
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
J2ee connector architecture
J2ee connector architectureJ2ee connector architecture
J2ee connector architecture
 
how to create object
how to create objecthow to create object
how to create object
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Introduction to network
Introduction to networkIntroduction to network
Introduction to network
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Text mode Linux Installation Part 01
Text mode Linux Installation Part 01Text mode Linux Installation Part 01
Text mode Linux Installation Part 01
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Último (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

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)
  • 6.
  • 7.
  • 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];
  • 10.
  • 11.
  • 12.
  • 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;
  • 15.
  • 16.
  • 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
  • 20.
  • 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.