- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Difference Between Pointer and Reference
In this post, we will understand the difference between pointer and reference.
Pointer
It can be initialized to any value.
It can be initialized any time after its declaration.
It can be assigned to point to a NULL value.
It can be dereferenced using the ‘*’ operator.
It can be changed to point to a different variable of the same type only.
Example
int val = 5; //code// int *p = &val;
Reference
It has to be initialized when it is declared.
It can’t be a NULL value.
It can be used by a name.
Once it has been initialized to a variable, it can’t be changed to refer to a variable object.
Example
int val = 52; int &ref = val;
Advertisements