What is the difference between Pointer and a Reference?
When you would use them?
Answer Posted / srihariraju
A reference just renames a memory location for the
reader/programmer. Its more like renaming a constant with
#define. The reference does not really 'contain' the
address, instead the comiler *could* just substitute the
address for the reference at the assembly code level.
A pointer is a variable (it 'must' have a memory location
of its own (barring odd compiler tricks)) that *can* be
used like a reference or it can point to nothing (NULL) (a
reference cannot do that) and a pointer can get new memory
from the os (new command) while a reference must 'point' to
existing memory.
| Is This Answer Correct ? | 14 Yes | 0 No |
Post New Answer View All Answers
Is c++ a pure oop language?
Distinguish between new and malloc and delete and free().
Write a C++ Program to check whether a number is prime number or not?
What does std :: flush do?
Define namespace in c++?
To which numbering system can the binary number 1101100100111100 be easily converted to?
Write about the role of c++ in the tradeoff of safety vs. Usability?
Write a program to encrypt the data in a way that inputs a four digit number and replace each digit by (the sum of that digit plus 7) modulus 10. Then sweep the first digit with the third, second digit with the fourth and print the encrypted number.
What is the average salary of a c++ programmer?
What is the benefit of encapsulation?
What is & in c++ function?
What is iostream in c++ used for?
Can you pass an array to a function in c++?
What is the array and initializing arrays in c++?
What is endl c++?