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

Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in Crgnikate
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expressionAkhil Ahuja
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationViji B
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and PointersPrabu U
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
 

What's hot (20)

Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Data types in php
Data types in phpData types in php
Data types in php
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expression
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Enums in c
Enums in cEnums in c
Enums in c
 

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
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
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++
 
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
 
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
 
Input Output Management In C Programming
Input Output Management In C ProgrammingInput Output Management In C Programming
Input Output Management In C Programming
 

Similar to Ponters

Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
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
 

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
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
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
 

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

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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.