SlideShare a Scribd company logo
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

PPTX
Pointers in c++
PDF
Pointers
PPT
Stacks
PPTX
Pointers in c++
PPTX
Pointer in c program
PDF
Pointer in c++ part1
PPTX
Pointer arithmetic in c
PPT
Pointers in c
Pointers in c++
Pointers
Stacks
Pointers in c++
Pointer in c program
Pointer in c++ part1
Pointer arithmetic in c
Pointers in c

What's hot (20)

PPTX
Typedef
PPTX
Presentation on pointer.
PPT
Pointers C programming
PPT
standard template library(STL) in C++
PPTX
Type Conversion, Precedence and Associativity
PDF
Functional Programming Patterns (NDC London 2014)
PPTX
Dynamic Polymorphism in C++
PPTX
Pointer in c
PDF
Python Variable Types, List, Tuple, Dictionary
PDF
C Pointers
PPTX
Dictionaries and Sets in Python
PPTX
16 dynamic-memory-allocation
PPT
16717 functions in C++
 
PDF
Python Intro
PPT
Pointer in C
PPTX
Constructor and Types of Constructors
PPT
C++ Pointers And References
PPTX
Pointers in c++
PPTX
Different types of Linked list.
PPT
Introduction to Python - Part Two
Typedef
Presentation on pointer.
Pointers C programming
standard template library(STL) in C++
Type Conversion, Precedence and Associativity
Functional Programming Patterns (NDC London 2014)
Dynamic Polymorphism in C++
Pointer in c
Python Variable Types, List, Tuple, Dictionary
C Pointers
Dictionaries and Sets in Python
16 dynamic-memory-allocation
16717 functions in C++
 
Python Intro
Pointer in C
Constructor and Types of Constructors
C++ Pointers And References
Pointers in c++
Different types of Linked list.
Introduction to Python - Part Two
Ad

Viewers also liked (20)

PPT
Unit 6 pointers
PPT
Pointers in C
PPT
PPTX
Pointers in C Programming
PPTX
intro to pointer C++
PPTX
Pointer in C++
PPTX
Learning C++ - Pointers in c++ 2
PPTX
C programming - Pointers
PPT
Pointers (Pp Tminimizer)
PPTX
This pointer
PPTX
PPT
C++ classes
PPT
02 c++ Array Pointer
PPTX
Oop c++class(final).ppt
PPTX
pointers,virtual functions and polymorphism
PDF
Pointers & References in C++
PPT
This pointer .17
PPT
Pointers+(2)
PPT
Introduction to pointers and memory management in C
Unit 6 pointers
Pointers in C
Pointers in C Programming
intro to pointer C++
Pointer in C++
Learning C++ - Pointers in c++ 2
C programming - Pointers
Pointers (Pp Tminimizer)
This pointer
C++ classes
02 c++ Array Pointer
Oop c++class(final).ppt
pointers,virtual functions and polymorphism
Pointers & References in C++
This pointer .17
Pointers+(2)
Introduction to pointers and memory management in C
Ad

Similar to C++ Pointers (20)

PDF
Pointers
ODP
Pointers in c++ by minal
PPTX
L4_Pointer Arithmetic in C++.pptxhwhwjwjw
PPTX
INTRODUCTION TO POINTER IN c++ AND POLYMORPHISM
PPTX
Object Oriented Programming using C++: Ch10 Pointers.pptx
PDF
Pointer in C++_Somesh_Kumar_Dewangan_SSTC
PPT
Lec 37 - pointers
PPT
POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
PPT
Pointers
PPTX
pointers.pptx
PPTX
Pf cs102 programming-9 [pointers]
PPT
Pointer
PPT
Lec 36 - pointers
PPTX
Computer Programming Lecture numer 05 -- pointers,variablesb
PDF
polymorphism in c++ with Full Explanation.
PPT
oop Lecture 17
PPTX
Object oriented programming slides for presentation
PPT
FP 201 - Unit 6
PPTX
POINTERS IN C
Pointers
Pointers in c++ by minal
L4_Pointer Arithmetic in C++.pptxhwhwjwjw
INTRODUCTION TO POINTER IN c++ AND POLYMORPHISM
Object Oriented Programming using C++: Ch10 Pointers.pptx
Pointer in C++_Somesh_Kumar_Dewangan_SSTC
Lec 37 - pointers
POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
Pointers
pointers.pptx
Pf cs102 programming-9 [pointers]
Pointer
Lec 36 - pointers
Computer Programming Lecture numer 05 -- pointers,variablesb
polymorphism in c++ with Full Explanation.
oop Lecture 17
Object oriented programming slides for presentation
FP 201 - Unit 6
POINTERS IN C

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”

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