Difference between Reference and Pointer in C++Last Updated : 13 Jan 2026 In C++, reference and pointer seem to be similar, but some differences exist between them. A reference is a variable that is another name of the existing variable, while the pointer is a variable that stores the address of another variable. In this article, we will discuss the difference between reference and pointer in C++. Before discussing their differences, we must know about references and pointers in C++. What is a Reference in C++?A reference is defined using the ampersand (&) symbol. An alias for an existing variable in C++ is a reference variable, which gives access to the same memory location with a different name. When we once initialized a reference to a variable, it cannot be modified to refer to another variable. C++ Reference ExampleLet us take an example to illustrate the reference in C++. ExampleCompile and RunOutput: The value of 'i' variable is :8 Explanation: In this example, we have created a reference variable, i.e., 'a' for 'i' variable. After creating a reference variable, we can access the value of 'i' with the help of 'a' variable. What is a Pointer in C++?A pointer is a variable that contains the address of another variable. It can be dereferenced with the help of (*) operator to access the memory location to which the pointer points. It can be utilized with any data type, such as arrays, basic data types, and user-defined types, including classes and structures. C++ Pointer ExampleLet us take an example to illustrate the pointer in C++. ExampleCompile and RunOutput: First number: 13 Second number: 9 Addition: 22 Explanation: In this example, we store the addresses of two integers x and y in pointers ptr1 and ptr2 and then access their values using dereferencing (*ptr1 and *ptr2) to calculate their sum. Finally, it prints the original values and the result of the addition. Key differences between Reference and PointerThere are several key differences between reference and pointer in C++. Some main differences are as follows: DefinitionIn C++, a reference variable is another name for an already existing variable. It is mainly used in 'pass by reference' where the reference variable is passed as a parameter to the function, and the function to which this variable is passed works on the original copy of the variable. On the other hand, a Pointer is a variable that stores the address of another variable. It makes the programming easier as it holds the memory address of some variable. DeclarationIn C++, a reference variable can be declared by adding a '&' symbol before a variable. If this symbol is used in the expression, it will be treated as an address operator. On the other hand, before using a pointer variable, we should declare a pointer variable, and this variable is created by adding a '*' operator before a variable. ReassignmentIn C++, we cannot reassign the reference variable. On the other hand, the pointers can be re-assigned. It is useful when we are working with the data structures, such as linked lists, trees, etc. Memory AddressIn the case of reference, both the reference and actual variable refer to the same address. A reference always refers to the same variable it was initialized with. It cannot be changed to refer to another variable. Reference Example: ExampleCompile and RunOutput: The address of 'a' variable is : 0x7fff078e7e44 The address of 'i' variable is : 0x7fff078e7e4 Explanation: The above output shows that both the reference variable and the actual variable have the same address. In the case of pointers, both the pointer variable and the actual variable will have different memory addresses. Pointer Example ExampleCompile and RunOutput: The memory address of p variable is :0x7ffef9ea3db0 The memory address of k variable is :0x7ffef9ea3dac NULL ValueIn C++, we cannot assign the NULL value to the reference variable. On the other hand, the pointer variable can be assigned with a NULL value. IndirectionIn C++, pointers can have a pointer to pointer, which offers more than one level of indirection. Pointer Example: ExampleCompile and RunOutput: The value of q is : 0x7fffc17a95f4 Explanation: In this example, the pointer 'p' is pointing to variable 'a' while 'q' is a double pointer that is pointing to 'p'. Therefore, we can say that the value of 'p' would be the address of the 'a' variable, and the value of the 'q' variable would be the address of the 'p' variable. On the other hand, references only contain one level of indirection in C++. Reference Example: ExampleCompile and RunOutput: main.cpp: In function 'int main()': main.cpp:18:10: error: cannot bind 'int' lvalue to 'int&&' int &&q=p; // Only valid with std::move Arithmetic OperationsIn C++, arithmetic operations can be applied to the pointers named "Pointer Arithmetic". On the other hand, arithmetic operations cannot be applied to the references. There is no word, i.e., Reference Arithmetic exists in C++. Difference between Reference and Pointer in Tabular FormHere, we will discuss several differences between references and pointers in tabular form in C++.
ConclusionIn conclusion, C++ references and pointers both provide several methods to access and manipulate data indirectly, but they can be served for different purposes. References are easy to understand and simple, which makes them suitable for parameter passing and aliasing. On the other hand, pointers provide greater flexibility, which enables null values, reassignment, and dynamic memory handling. We can choose these methods based on our requirements. References are suitable when simplicity and safety are required, and pointers when more control and dynamic behaviour are required. Next TopicFunction Pointer in C++ |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India