SlideShare a Scribd company logo
1 of 9
Lecture 7
ChaaND Sheikh
Pointers.
//Demonstration.
#include<conio.h>
Every Block is
#include<iostream.h>
a memory cell
void main()
{
Cell no’s / Address
int x ;
float y;
x = 10;

Memory
4001

4002

4003

4004

4005

4006

4007

4008

4009

10

x
y

4007
y = 20.0;

}

cout<<“Value’s of x and y = “<<x<<y;
getch();
4007

20.0

4002
• Pointers deals with memory address, using pointers we
can access memory directly. storing pointer type entity
we need special type variables.
•

data-type * Variable_name;
Type of data
stored in the
address of
the variable.

Indirection
operator
&

*

Address of (Reference) Operator.
Value At Address (Indirection) operator.

void main()
20.0
Value at Address.
{
int *int_ptr;
10
float *float_ptr;
Address
4002
4007
int x = 10 ;
x
y
Name od address
float y = 20.0;
cout<<“Value’s of x and y = “<<x<<“ “<<y;
int_ptr = &x;
float_ptr = &y;
cout<<"int_ptr = "<<int_ptr;
cout<<"n float_ptr = "<<float_ptr;
cout<<"n value in int_pointer = "<< *int_ptr;
cout<<"n value in float_ptr = "<< *float_ptr;
getch(); }
&

Address of (Reference) Operator.

*

Value At Address (Indirection) operator.

// Demonstration.
#include <iostream.h>
#include<conio.h>
void main ()
{
int variable ;
int *mypointer;
mypointer = &variable;
*mypointer = 50;

50
3722
variable

Address of variable = mypointer
50 = value at address

cout << "value in variable is " <<variable<<endl;
getch();
}
Value in variable is 50
//Demonstration
& Address of (Reference) Operator.
#include <iostream.h>
* Value At Address (Indirection) operator.
#include<conio.h>
main ()
{
10
5888
2554
int x=10;
int *y;
2554
5888
6550
int **z;
**z
x
*y
cout<<"Value of x = "<<x;
cout<<"nAdd of x = "<<&x;
Value of x = 10
cout<<"nValue of x = "<<*(&x);
Add of x = 2554
y=&x;
cout<<"nAdd of y = "<<&y;
Value of x = 10
cout<<"nAdd in y = "<<y;
Add of y = 5888
z=&y;
cout<<"nAdd of z = "<<&z;
Add in y = 2554
cout<<"nAdd in z = "<<z;
getch();
Add of y = 6550
}
Add in z = 5888
//Demonstration

& Address of (Reference) Operator.

#include <iostream.h>
* Value At Address (Indirection) operator.
#include<conio.h>
main ()
{
10
5888
2554
int x=10;
2554
5888
6550
int *y;
**z
x
*y
int **z;
cout<<"Value of x = "<<x;
cout<<"nAdd of x = "<<&x;
Value of x = 10
y=&x;
Add of x = 2554
cout<<“Accessing x via ptr y = ”<<*y;
z=&y;
x via prt y = 10
cout<<“Accessing x via ptr z ”<<**z;
x via prt z = 10
getch();
}
&

Address of (Reference) Operator.

*

Value At Address (Indirection) operator.

1. *& variable = variable
2. *(&)variable = *&variable
Example 1 :
int x =10;
cout<<*&x;
10
cout<<*(&)x;
Example 2 :
int x = 10;
int * p;
p = &x;
cout<<* p;

10

More Related Content

What's hot

10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
웅식 전
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
rohassanie
 

What's hot (20)

Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
This pointer
This pointerThis pointer
This pointer
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Arrays
ArraysArrays
Arrays
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
pointers
pointerspointers
pointers
 

Viewers also liked

Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
tech4us
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
This pointer .17
This pointer .17This pointer .17
This pointer .17
myrajendra
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 

Viewers also liked (20)

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++
 
Pointers
PointersPointers
Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C Pointers
C PointersC Pointers
C Pointers
 
Ponters
PontersPonters
Ponters
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C pointer
C pointerC pointer
C pointer
 
C++ classes
C++ classesC++ classes
C++ classes
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
This pointer .17
This pointer .17This pointer .17
This pointer .17
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 

Similar to C++ Pointers

Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
Abdul Samee
 
Tugas praktikukm pemrograman c++
Tugas praktikukm  pemrograman c++Tugas praktikukm  pemrograman c++
Tugas praktikukm pemrograman c++
Dendi Riadi
 
Part APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docxPart APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docx
dewhirstichabod
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 

Similar to C++ Pointers (20)

Pointers
PointersPointers
Pointers
 
Unit 3
Unit 3Unit 3
Unit 3
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Pointer
PointerPointer
Pointer
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
C++ examples &revisions
C++ examples &revisionsC++ examples &revisions
C++ examples &revisions
 
Pointers
PointersPointers
Pointers
 
P1
P1P1
P1
 
Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
 
Tugas praktikukm pemrograman c++
Tugas praktikukm  pemrograman c++Tugas praktikukm  pemrograman c++
Tugas praktikukm pemrograman c++
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"Max Koretskyi "Why are Angular and React so fast?"
Max Koretskyi "Why are Angular and React so fast?"
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
Part APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docxPart APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docx
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Pointers
PointersPointers
Pointers
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

C++ Pointers

  • 3. //Demonstration. #include<conio.h> Every Block is #include<iostream.h> a memory cell void main() { Cell no’s / Address int x ; float y; x = 10; Memory 4001 4002 4003 4004 4005 4006 4007 4008 4009 10 x y 4007 y = 20.0; } cout<<“Value’s of x and y = “<<x<<y; getch(); 4007 20.0 4002
  • 4. • Pointers deals with memory address, using pointers we can access memory directly. storing pointer type entity we need special type variables. • data-type * Variable_name; Type of data stored in the address of the variable. Indirection operator
  • 5. & * Address of (Reference) Operator. Value At Address (Indirection) operator. void main() 20.0 Value at Address. { int *int_ptr; 10 float *float_ptr; Address 4002 4007 int x = 10 ; x y Name od address float y = 20.0; cout<<“Value’s of x and y = “<<x<<“ “<<y; int_ptr = &x; float_ptr = &y; cout<<"int_ptr = "<<int_ptr; cout<<"n float_ptr = "<<float_ptr; cout<<"n value in int_pointer = "<< *int_ptr; cout<<"n value in float_ptr = "<< *float_ptr; getch(); }
  • 6. & Address of (Reference) Operator. * Value At Address (Indirection) operator. // Demonstration. #include <iostream.h> #include<conio.h> void main () { int variable ; int *mypointer; mypointer = &variable; *mypointer = 50; 50 3722 variable Address of variable = mypointer 50 = value at address cout << "value in variable is " <<variable<<endl; getch(); } Value in variable is 50
  • 7. //Demonstration & Address of (Reference) Operator. #include <iostream.h> * Value At Address (Indirection) operator. #include<conio.h> main () { 10 5888 2554 int x=10; int *y; 2554 5888 6550 int **z; **z x *y cout<<"Value of x = "<<x; cout<<"nAdd of x = "<<&x; Value of x = 10 cout<<"nValue of x = "<<*(&x); Add of x = 2554 y=&x; cout<<"nAdd of y = "<<&y; Value of x = 10 cout<<"nAdd in y = "<<y; Add of y = 5888 z=&y; cout<<"nAdd of z = "<<&z; Add in y = 2554 cout<<"nAdd in z = "<<z; getch(); Add of y = 6550 } Add in z = 5888
  • 8. //Demonstration & Address of (Reference) Operator. #include <iostream.h> * Value At Address (Indirection) operator. #include<conio.h> main () { 10 5888 2554 int x=10; 2554 5888 6550 int *y; **z x *y int **z; cout<<"Value of x = "<<x; cout<<"nAdd of x = "<<&x; Value of x = 10 y=&x; Add of x = 2554 cout<<“Accessing x via ptr y = ”<<*y; z=&y; x via prt y = 10 cout<<“Accessing x via ptr z ”<<**z; x via prt z = 10 getch(); }
  • 9. & Address of (Reference) Operator. * Value At Address (Indirection) operator. 1. *& variable = variable 2. *(&)variable = *&variable Example 1 : int x =10; cout<<*&x; 10 cout<<*(&)x; Example 2 : int x = 10; int * p; p = &x; cout<<* p; 10