SlideShare a Scribd company logo
1 of 14
 
Pointers ,[object Object],[object Object],[object Object],[object Object]
Concept of Address and Pointers ,[object Object],[object Object],[object Object],Contents1 Contents11 Contents16 ADDR1 ADDR2 ADDR3 ADDR4 ADDR5 ADDR6 * * * ADDR11 * * ADDR16
POINTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
POINTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
POINTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
POINTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Use of & and * ,[object Object],[object Object],[object Object],[object Object]
POINTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers and Functions ,[object Object],[object Object],[object Object]
Pointers and Functions ,[object Object],[object Object]
Pointers with Functions (example) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Arithmetic and Logical Operations on Pointers ,[object Object],[object Object],[object Object],[object Object]
Arithmetic Operations on Pointers ,[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot (20)

Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers
PointersPointers
Pointers
 
C string
C stringC string
C string
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
5 nested if in c with proper example
5 nested if in c with proper example5 nested if in c with proper example
5 nested if in c with proper example
 
C Programming : Pointers and Arrays, Pointers and Strings
C Programming : Pointers and Arrays, Pointers and StringsC Programming : Pointers and Arrays, Pointers and Strings
C Programming : Pointers and Arrays, Pointers and Strings
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Input buffering
Input bufferingInput buffering
Input buffering
 
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
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 

Viewers also liked (20)

C Pointers
C PointersC Pointers
C Pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Pointers - DataStructures
Pointers - DataStructuresPointers - DataStructures
Pointers - DataStructures
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 
C chap02
C chap02C chap02
C chap02
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
[UX Project] C-Saw
[UX Project] C-Saw[UX Project] C-Saw
[UX Project] C-Saw
 

Similar to Ponters

Cplusplus
CplusplusCplusplus
Cplusplusdancey
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfsudhakargeruganti
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptgeorgejustymirobi1
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function웅식 전
 
4 operators, expressions & statements
4  operators, expressions & statements4  operators, expressions & statements
4 operators, expressions & statementsMomenMostafa
 
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
 

Similar to Ponters (20)

iit c prog.ppt
iit c prog.pptiit c prog.ppt
iit c prog.ppt
 
C programming
C programmingC programming
C programming
 
Cplusplus
CplusplusCplusplus
Cplusplus
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Session 5
Session 5Session 5
Session 5
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
About Go
About GoAbout Go
About Go
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).ppt
 
c program.ppt
c program.pptc program.ppt
c program.ppt
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
4 operators, expressions & statements
4  operators, expressions & statements4  operators, expressions & statements
4 operators, expressions & statements
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
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
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Lk module5 pointers
Lk module5 pointersLk module5 pointers
Lk module5 pointers
 
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
 

More from Mukund Trivedi

More from Mukund Trivedi (20)

System development life cycle (sdlc)
System development life cycle (sdlc)System development life cycle (sdlc)
System development life cycle (sdlc)
 
Process of design
Process of designProcess of design
Process of design
 
New file and form 2
New file and form 2New file and form 2
New file and form 2
 
File organisation
File organisationFile organisation
File organisation
 
Evaluation
EvaluationEvaluation
Evaluation
 
Database
DatabaseDatabase
Database
 
Case tools
Case toolsCase tools
Case tools
 
Evaluation
EvaluationEvaluation
Evaluation
 
Dfd final
Dfd finalDfd final
Dfd final
 
Sad
SadSad
Sad
 
C++ file
C++ fileC++ file
C++ file
 
Ff40fnatural resources (1)
Ff40fnatural resources (1)Ff40fnatural resources (1)
Ff40fnatural resources (1)
 
Ff40fnatural resources
Ff40fnatural resourcesFf40fnatural resources
Ff40fnatural resources
 
F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)
 
F58fbnatural resources 2
F58fbnatural resources 2F58fbnatural resources 2
F58fbnatural resources 2
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
Ee2fbunit 7
Ee2fbunit 7Ee2fbunit 7
Ee2fbunit 7
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Ponters

  • 1.  
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

Editor's Notes

  1. We have already used pointer without knowing it when they declare FILE variables, which basically point to the address where a file stream is located. Pointers are variables that contain instead of data, the memory address where the data exists as their values. It can be said that a regular variable name directly references the value in that variable. A pointer, on the other hand, indirectly references a value. Referencing through a pointer is called indirection. Like any other variable, a pointer must be declared before it can be used.
  2. A computer has two basic types of busses to the memory: an address and data bus. Thus far we have been concerned mainly with the data we store but not its storage location. Pointers allow us to also use the address in which our data is stored in various ways. This conceptualization of memory can be likened to a street with various address where mail is delivered. The mailman delivers the correct data (letters) to the correct address written on each piece of mail.
  3. Pointers can be declared with regular variables in the same line, the asterisk (or lack of one) determines if the variable will contain an address or data. It is important to declare the correct type of pointer depending on the type of data it will point to. It is NOT possible to give a variable and pointer the same name. All variables (pointer or data) must still have a unique name. Pointers are declared much like variables, except an asterisk must be before each variable name. Pointers can be declared with regular variables in the same line, the asterisk (or lack of one) determines if the variable will contain an address or data. It is important to declare the correct type of pointer depending on the type of data it will point to. It is NOT possible to give a variable and pointer the same name. All variables (pointer or data) must still have a unique name.
  4. In this case the pointer and variable declarations are separated. They could have also been handled as such: FILE *fptr1, *fptr2; int *aptr, a; int *bptr, b; In these statements we are declaring pointers of multiple types, along with the familiar FILE pointer type. We also declare normal variables. In this case the pointer and variable declarations are separated. Pointers and variables of the same type could have been declared on the same line, separated by commas.
  5. Remember that including the ampersand (&) before any variable’s name returns its location in memory (first introduced with scanf() and fscanf()). So to set a pointer to the location in memory of a variable we simply set the pointer equal to the variable with a preceding ampersand such as those shown. We can then use the fscanf with the pointers aptr and bptr instead of &a and &b since both return the same information (the memory location of variables a and b).
  6. Remember fprintf() returns the value stored in a variable (without the need of a preceding ampersand). 1 st fprintf: returns the values stored in aptr and bptr (the memory locations of a and b). (the addresses) 2 nd fprintf: returns the values stored in the memory locations stored in aptr and bptr (the actual values of a and b). (the data) – called dereferencing a pointer 3 rd fprintf: returns the values of a and b (the data) 4 th fprintf: returns the memory locations of a and b (the addresses) Notice the difference in the variables printed in each fprintf() function here. Can you determine which variable will print which values? 1 st fprintf: returns the values stored in aptr and bptr (the memory locations of a and b). (the addresses) 2 nd fprintf: returns the values stored in the memory locations stored in aptr and bptr (the actual values of a and b). (the data) – called dereferencing a pointer 3 rd fprintf: returns the values of a and b (the data) 4 th fprintf: returns the memory locations of a and b (the addresses)
  7. Use the & when you wish to know the address of a variable. Use the * when you wish to return the value stored in the variable as an address , then look in that address and return its data With the introduction of pointers, we now have the & and the * being used for various operations. The & is used when you wish to know the address of a variable. This is known as the address operator. The *, or dereferencing operator, provides the contents of the memory location specified by a pointer. This operation takes the value stored in the pointer as an address, looks in that address and returns the data stored there.
  8. The output of this program is simulated with two values from an input file and output given in the right column. The numbers representing addresses in this example would change if each student were to execute the program (each student would receive their own block of memory to use) and may also change during each execution of the program depending on if the operating system keeps the program cached after each use. The output of this program is simulated with two values from an input file and output given in the right column. As expected, pointers and variables with address operators return the addresses of the a and b variables. Also the dereferenced pointers and variables themselves return the values of the variables. The numbers representing addresses in this example would change if you were to execute the program and may also change during each execution of the program depending on if the operating system keeps the program cached after each use
  9. Looking back as the swap function problem, the variable scope problem can now be solved by passing pointers, or the original location of variables, instead of just the values. The next slide explains more. So now we can see how pointers can be used to pass addresses of variables around. They can also be used to pass addresses of variables to functions, thus allowing the function to alter the values of the original variables. Looking back at the swap function, you may remember it received copies of the variables, since they were called by value.
  10. Call by reference is now explained. It simply involves passing the location in memory of the original variables to any supporting function. If instead of passing the value of variables to the function, we now pass the addresses so that the function can change the values stored in the calling routine. The is known as “called by reference” since we are referencing the variables. The swap function is shown again modified to call by reference instead of call by value. This will now actually swap the values in the function, and will return to the main with actual swapped values.
  11. Here is a modified swap program. Notice the swap function now requires pointer variables as input (both in the function and function prototype), and that all operations are done by dereferencing the pointers within the swap function to get the values and move them around with the aid of the local “temp” variable. In the main() function the addresses of the a and b variable are passed to the swap() function (given by &a and &b). The results are now what would be expected of a swap function.
  12. Most logical operations can be used on pointers as with regular variables, but the programmer must be careful of the results since each program doesn’t have free reign of the entire computer’s memory space. Errors which attempt to use memory not assigned to a certain program will cause what will be seen as a segmentation fault or bus error in UNIX, or Windows’ extreme, more deadly blue screen of death. Pointers can be incremented and decremented. Integers can be added or subtracted from a pointer, and pointers variable may be subtracted from one another. Pointers can also be used in comparisons, but usually only in a comparison to NULL as been shown when testing file pointers for a successful file open.
  13. Memory arithmetic is slightly more complicated than standard algebra. Each byte of memory has its own unique address. Remember that different data types use multiple bytes of memory thus span multiple addresses. The UNIX data sizes are reviewed: int: 32 bit – 4 bytes float: 32 bit – 4 bytes double: 64 bit – 8 bytes char: 8 bit – 1 byte So addition of y to a pointer will actually be a multiple of y*x where x is the size of the data type in bytes. In the example shown here, the pointer valptr contains the address of a double precision variable and the address is shown. Each double precision number is 8 bytes. The addition of 2 to the pointer is then 2*8, or 16. Thus we can see the addition of 2 to the pointer adds 16 to the address.