
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What is difference between a pointer and reference parameter in C++?
Pointers
Pointer variables are used to store the address of variable.
Syntax
Type *pointer;
Initialization
Type *pointer; Pointer=variable name;
References
When a parameter is declared as reference, it becomes an alternative name for an existing parameter.
Syntax
Type &newname=existing name;
Initialization
Type &pointer; Pointer=variable name;
The main differences between pointers and reference parameters are −
References are used to refer an existing variable in another name whereas pointers are used to store address of variable.
References cannot have a null value assigned but pointer can.
A reference variable can be referenced by pass by value whereas a pointer can be referenced by pass by reference.
A reference must be initialized on declaration while it is not necessary in case of 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
- Difference Between Pointer and Reference
- What is the difference between a weak reference and an unowned reference?
- What are the differences between a pointer variable and a reference variable in C++?
- In C++ What are the differences between a pointer variable and a reference variable?
- What is the difference between object and reference in java?
- Difference Between Array and Pointer
- What is a reference/ref parameter of an array type in C#?
- Explain reference and pointer in C programming?
- Difference between pointer and array in C
- What is the difference between pass by value and reference parameters in C#?
- Difference between OSI and TCP/IP Reference Model
- Why do we pass a Pointer by Reference in C++?
- Difference between Call by Value and Call by Reference
- Passing by pointer Vs Passing by Reference in C++
- Differences between Method Reference and Constructor Reference in Java?
