- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pointers vs References in C++
Pointers are used to store the address of variable.
Type *pointer; pointer = variable name;
When a variable is declared as reference, it becomes an alternative name for an existing variable.
Type &newname = existing name;
Type &pointer; pointer = variable name;
The main differences between pointers and references 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 but 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.
- C/C++ Pointers vs Java references
- When to use references vs. pointers in C/C++
- Pointers, smart pointers and shared pointers in C++
- References in C++
- What is the difference between Java references and pointers in other languages?
- Pointers in C/C++
- Applications of Pointers in C/C++
- What are circular references in C#?
- What are pointers in C#?
- C++ vs C++0x vs C++11 vs C++98
- Examples of soft references and phantom references?
- PHP References
- What are Wild Pointers in C/C++?
- How to compare pointers in C/C++?
- RAII and smart pointers in C++