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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

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