C++ Programming - References - Discussion

Discussion Forum : References - General Questions (Q.No. 2)
2.
Which of the following statements is correct?
  1. Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
  2. A reference is not a constant pointer.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
16 comments Page 1 of 2.

Nidhi said:   1 decade ago
2 is correct
becuase a refrence can be thaught of as (*p) where we can not change p is true but a is value at that pointer
so a reference is a value_at-cannot_be_changed_by_us-pointer
and is not a constant pointer

Sireesha said:   1 decade ago
You can always change the address being pointed by 'p' and also value at 'p' unless they are constant similar is the case with the reference variable.

Ashish said:   1 decade ago
Can anyone please explain. Why the 2nd option is incorrect?

Karthik said:   1 decade ago
2 is incorrect because reference once created alias i.e., initialized with the variable must not be assigned once again with the another new another. So, it seems like const pointer.

Yadav said:   1 decade ago
Pointer can change its reference, it is not a constant.

What does the second statement mean?

A reference is not a constant pointer.

Chanchal said:   1 decade ago
Pointer take the reference of another variable also and it is not a constant pointer because we can change it.

AKAK said:   1 decade ago
- Pointer has its own address. Reference (const or not) does not.

- Const pointer can be NULL. Reference can not.

- You can test for NULL pointer being returned by a function. You cannot test for NULL-reference, even if object being referenced went out of scope.

- You need to deference the pointer to access it's data, there is no deference a reference.

All that makes references conceptually and practically different from const pointers, even though under the hood they can be implemented as the same mechanism by a compiler.

Daniel Sandor said:   10 years ago
"The C++ standard does not force compilers to implement references using.

Daniel Sandor said:   10 years ago
"The C++ standard does not force compilers to implement references using pointer.

Bhasker Bamsiya said:   9 years ago
The Answer mentioned is wrong.

A reference variable can't refer to any other variable once it has been defined to refer to a particular variable.

The correct answer should be option [B].
(1)


Post your comments here:

Your comments will be displayed after verification.