C++ References

  Home  C++ Programming  C++ References


“C++ References frequently Asked Questions in various C++ References job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”



16 C++ References Questions And Answers

1⟩ What is the difference between pointer and reference?

When a reference is created, it can’t reference another object. This can be done with pointers. References cannot be null whereas pointers can be. References cannot be uninitialized and it is not possible to refer directly to a reference object after it is defined.

Example:

Syntax of reference:

<Type> & <Name>

int& rA = A; rA is a reference to int.

 219 views

2⟩ What are References in C++?

A restricted type of pointer in C++ is known as a reference. A reference can be assigned only once and can not have a null value.

 228 views

5⟩ What is reference variable?

A reference variable is just like pointer with few differences. It is declared using & operator. A reference variable must always be initialized. The reference variable once defined to refer to a variable can’t be changed to point to other variable. You can't create an array of references the way it is possible with pointer.

 219 views

6⟩ What means pass by pointer?

The callee function receives a pointer to the variable. The value of the pointer in the caller function can then be modified. The advantages of this process are that the changes are passed back to the caller function and multiple variables can be changed.

 242 views

7⟩ What means pass by reference?

The callee function receives a set of references which are aliases to variables. If a change is made to the reference variable, the original value (passed by the caller function) will also be changed. All the references are handled by the pointers. Multiple values modification can be done by passing multiple variables.

 232 views

8⟩ What means pass by value?

The callee function receives a set of values that are to be received by the parameters. All these copies of values have local scope, i.e., they can be accessed only by the callee function. The simplicity and guarantee of unchanging of values passed are the advantages of pass by value.

 222 views

14⟩ What is the output of this program? #include <iostream> using namespace std; void swap(int &a, int &b); int main() { int a = 5, b = 10; swap(a, b); cout << "In main " << a << b; return 0; } void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; cout << "In swap " << a << b; } a) In swap 105 In main 105 b) In swap 105 In main 510 c) In swap 510 In main 105 d) none of the mentioned

a) In swap 105 In main 105

 277 views