C++ References Interview Questions And Answers
Download C++ References Interview Questions and Answers PDF
Refine your C++ References interview skills with our 16 critical questions. These questions are specifically selected to challenge and enhance your knowledge in C++ References. Perfect for all proficiency levels, they are key to your interview success. Don't miss out on our free PDF download, containing all 16 questions to help you succeed in your C++ References interview. It's an invaluable tool for reinforcing your knowledge and building confidence.
16 C++ References Questions and Answers:
C++ References Job Interview Questions Table of Contents:
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.
Read MoreExample:
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.
Read More3 :: 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.
Read More4 :: 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.
Read More5 :: 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.
Read More6 :: 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.
Read More7 :: 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.
Read More8 :: 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.
Read More9 :: Identify the incorrect statement:
a) reference is the alternate name of the object
b) A reference value once defined can be reassigned
c) A reference value once defined cannot be reassigned
d) none of the mentioned
c) A reference value once defined cannot be reassigned
Read More10 :: 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
Read More11 :: What is output of program?
#include <iostream>
using namespace std;
void print (char * a)
{
cout << a << endl;
}
int main ()
{
const char * a = "Hello world";
print(const_cast<char *> (a) );
return 0;
}
a) Hello world
b) Hello
c) world
d) compile time error
a) Hello world
Read More12 :: What is output of this program?
#include <iostream>
using namespace std;
int main()
{
int a = 9;
int & aref = a;
a++;
cout << "The value of a is " << aref;
return 0;
}
a) 9
b) 10
c) error
d) 11
b) 10
Read More13 :: Which value we cannot assign to reference?
a) integer
b) floating
c) unsigned
d) null
d) null
Read More14 :: Identify the correct sentence regarding inequality between reference and pointer.
a) we can not create the array of reference.
b) we can create the Array of reference.
c) we can use reference to reference.
d) none of the mentioned
a) we can not create the array of reference.
Read More15 :: What does a reference provide?
a) Alternate name for the class
b) Alternate name for the variable
c) Alternate name for the pointer
d) none of the mentioned
b) Alternate name for the variable
Read More16 :: Which reference modifier is used to define reference variable?
a) &
b) $
c) #
d) none of the mentioned
a) &
Read More