SlideShare a Scribd company logo
1 of 22
POINTERS INC++
BY -
SAI TARLEKAR
Points
 Introduction.
 Declaration and initialization of pointers.
 Small program.
 Thumb rule.
 Pointer Variable.
 Pointer Arithmetic.
 Reference Variable.
 Reference as function arguments
What is a Pointer???
 A pointer is a variable which holds the memory address
of another variable.
 This memory address is the location of another variable
where it has been stored as memory.
 Therefore if a variable contains the address of another
variable is said to point to the second.
Declaration and Initialization of
Pointers
 Syntax : Datatype *variable_name;
eg. int *x;
float *y;
char *z;
eg. int x = 10;
int *ptr = &x;
 Now ptr will contain address where the variable x is stored in memory.
int *ptr;
This tells the compiler three things about ptr:-
1) The (*) tells that the variable ptr is a pointer
variable.
2) Pointers need a memory location.
3) Pointers points to a variable of type int.
Program
Output:-
More info….
1) A pointer that is not initialzed is called as wild pointer
because you have no idea what it is pointing to.
2) A pointer whose value is zero is called as null pointer.
3) Void pointer - void pointer is a special type of pointer
that can be pointed at objects of any data type. A void
pointer is declared using data type void.
Thumb rule of pointers:-
1) Type must be same to the variable whose address is going
to pass to the pointer.
2) When you want to pass the address of the variable use ‘&’
before the variable name.
3) When you want to pass the value of the variable use ‘*’
before the pointer.
Pointer operator
 A pointer operator or a pointer variable is represented by a
combination of asterisk(*) with a variable name.
Syntax:-
data_type *pointer_variable;
eg. If a variable of character data type and also declared as *
(asterisk) with another variable it means the variable is of type
“Pointer to character”.
char *ptr;
where ptr is a pointer variable which holds the address of an
character data type.
Address Operator
 An address operator can be represented by a combination of and (ampersand)
with a pointer variable.
 The and is a unary operator that returns the memory address of its operand.
Syntax:-
data_type variable1;
data_type variable=&variable1;
Eg:-
int x;
int *ptr=&x;
It means that ptr receives the address of x;
Pointer Arithmetic
 Two arithmetic operations, addition and subtraction, may be
performed on pointers. When we add 1 to a pointer, we are
actually adding the size of data type in bytes, the pointer is
pointing at.
Eg. int *x; x++;
 If current address of x is 1000, then x++ statement will increase x
by 2(size of int data type) and makes it 1002, not 1001.
Data is stored in contiguous memory cell.
The Number of memory cells required to store a
data item depends on the type of data item
Char 1 byte
Integer 2 byte
Floating 4 byte
Double 8 byte
Program
Output:-
REFERENCE VARIABLE
A reference variable is a name that acts as an alias or an alternative name,
for an already existing variable.
Syntax:-
Data type &variable name = already existing variable;
Eg. int num=10;
int & sum = num; // sum is a reference variable or alias name for
num
NOTE: Both num and sum refer to the same memory location. Any changes made to the sum
will also be reflected in num.
10
sum
num
void cube(int &x)
{
x= x*x*x;
}
void main()
{
int y=10;
cout<<y<<endl;
cube(y);
cout<<y<<endl;
}
x
In the above program reference of y is passed. No separate
memory is allocated to x and it will share the same memory
as y. Thus changes made to x will also be reflected in y.
OUTPUT:
10
1000
REFERENCE AS FUNCTION ARGUMENTS
y
100
Program
#include<iostream.h>
#include<conio.h>
swap(int *,int *)
void main()
{
int a,b;
cout<<"nEnter value for A : ";
cin>>a;
cout<<"nEnter value for B : ";
cin>>b;
cout<<"nnBefore Swapping : ";
cout<<"nttta = "<<a;
cout<<"ntttb = "<<b;
swap(&a,&b);
cout<<"nnAfter Swapping : ";
cout<<"nttta = "<<a;
cout<<"ntttb = "<<b;
getch();
}
swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:-
Pointers in c++

More Related Content

What's hot (20)

Function in C program
Function in C programFunction in C program
Function in C program
 
Structure in c
Structure in cStructure in c
Structure in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
File in C language
File in C languageFile in C language
File in C language
 
C Pointers
C PointersC Pointers
C Pointers
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
C functions
C functionsC functions
C functions
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 

Viewers also liked

Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)Mohd Effandi
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2ppd1961
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in CUri Dekel
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...cprogrammings
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismrattaj
 

Viewers also liked (11)

Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
Pointers
PointersPointers
Pointers
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 

Similar to Pointers in c++ (20)

C pointers and references
C pointers and referencesC pointers and references
C pointers and references
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointers
PointersPointers
Pointers
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Pointers
PointersPointers
Pointers
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdf
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Pointers
PointersPointers
Pointers
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 

Recently uploaded

Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 

Recently uploaded (20)

Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 

Pointers in c++

  • 2. Points  Introduction.  Declaration and initialization of pointers.  Small program.  Thumb rule.  Pointer Variable.  Pointer Arithmetic.  Reference Variable.  Reference as function arguments
  • 3. What is a Pointer???  A pointer is a variable which holds the memory address of another variable.  This memory address is the location of another variable where it has been stored as memory.  Therefore if a variable contains the address of another variable is said to point to the second.
  • 4. Declaration and Initialization of Pointers  Syntax : Datatype *variable_name; eg. int *x; float *y; char *z; eg. int x = 10; int *ptr = &x;  Now ptr will contain address where the variable x is stored in memory.
  • 5. int *ptr; This tells the compiler three things about ptr:- 1) The (*) tells that the variable ptr is a pointer variable. 2) Pointers need a memory location. 3) Pointers points to a variable of type int.
  • 8.
  • 9. More info…. 1) A pointer that is not initialzed is called as wild pointer because you have no idea what it is pointing to. 2) A pointer whose value is zero is called as null pointer. 3) Void pointer - void pointer is a special type of pointer that can be pointed at objects of any data type. A void pointer is declared using data type void.
  • 10. Thumb rule of pointers:- 1) Type must be same to the variable whose address is going to pass to the pointer. 2) When you want to pass the address of the variable use ‘&’ before the variable name. 3) When you want to pass the value of the variable use ‘*’ before the pointer.
  • 11.
  • 12. Pointer operator  A pointer operator or a pointer variable is represented by a combination of asterisk(*) with a variable name. Syntax:- data_type *pointer_variable; eg. If a variable of character data type and also declared as * (asterisk) with another variable it means the variable is of type “Pointer to character”. char *ptr; where ptr is a pointer variable which holds the address of an character data type.
  • 13. Address Operator  An address operator can be represented by a combination of and (ampersand) with a pointer variable.  The and is a unary operator that returns the memory address of its operand. Syntax:- data_type variable1; data_type variable=&variable1; Eg:- int x; int *ptr=&x; It means that ptr receives the address of x;
  • 14. Pointer Arithmetic  Two arithmetic operations, addition and subtraction, may be performed on pointers. When we add 1 to a pointer, we are actually adding the size of data type in bytes, the pointer is pointing at. Eg. int *x; x++;  If current address of x is 1000, then x++ statement will increase x by 2(size of int data type) and makes it 1002, not 1001.
  • 15. Data is stored in contiguous memory cell. The Number of memory cells required to store a data item depends on the type of data item Char 1 byte Integer 2 byte Floating 4 byte Double 8 byte
  • 18. REFERENCE VARIABLE A reference variable is a name that acts as an alias or an alternative name, for an already existing variable. Syntax:- Data type &variable name = already existing variable; Eg. int num=10; int & sum = num; // sum is a reference variable or alias name for num NOTE: Both num and sum refer to the same memory location. Any changes made to the sum will also be reflected in num. 10 sum num
  • 19. void cube(int &x) { x= x*x*x; } void main() { int y=10; cout<<y<<endl; cube(y); cout<<y<<endl; } x In the above program reference of y is passed. No separate memory is allocated to x and it will share the same memory as y. Thus changes made to x will also be reflected in y. OUTPUT: 10 1000 REFERENCE AS FUNCTION ARGUMENTS y 100
  • 20. Program #include<iostream.h> #include<conio.h> swap(int *,int *) void main() { int a,b; cout<<"nEnter value for A : "; cin>>a; cout<<"nEnter value for B : "; cin>>b; cout<<"nnBefore Swapping : "; cout<<"nttta = "<<a; cout<<"ntttb = "<<b; swap(&a,&b); cout<<"nnAfter Swapping : "; cout<<"nttta = "<<a; cout<<"ntttb = "<<b; getch(); } swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; }