C++ References Interview Preparation Guide
Download PDF

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.

2 :: 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.

3 :: 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.

4 :: 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.

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.

6 :: What is a local reference?

A reference which has a local scope i.e., in a method or in a block or in a function is known as local reference.

7 :: 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.

8 :: Can you please explain the difference between pass by value and pass by reference?

In pass by value approach, the called function creates another copies of the variables passes as arguments. In this approach, the values of the original variables remain unchanged. However, we come across situations where we need to change the values of the original variables. Then the values may b passed by reference.