- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the differences between a pointer variable and a reference variable in C++?
References
When a variable is declared as a reference, it becomes an alternative name for an existing variable.
Syntax
Type &newname = existing name;
Initialization
Type &pointer; pointer = variable name;
Pointers
Pointers are used to store the address of a variable.
Syntax
Type *pointer;
Initialization
Type *pointer; pointer = variable name;
The main differences between references and pointers are -
- References are used to refer an existing variable in another name whereas pointers are used to store the address of a variable.
- References cannot have a null value assigned but pointer can.
- A reference variable can be referenced bypass by value whereas a pointer can be referenced but pass by reference
- A reference must be initialized on declaration while it is not necessary in case of a pointer.
- A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack.
- Related Articles
- In C++ What are the differences between a pointer variable and a reference variable?
- What is a reference variable in C++?
- What is difference between a pointer and reference parameter in C++?
- How to assign a reference to a variable in C#
- Defining a variable reference in SAP ABAP
- Difference Between Pointer and Reference
- Can we assign a reference to a variable in Python?
- What is different between constant and variable in C++?
- What is the difference between Declaring and Initializing a variable in JavaScript?
- What is the difference between a variable and StringVar() of Tkinter?
- Explain reference and pointer in C programming?
- Differences between Method Reference and Constructor Reference in Java?
- What are the differences between a class and a structure in C#?
- What are the differences between a class and struct in C#?
- What is a variable?

Advertisements