References C++ MCQ

Errorlogger
0
1. Which value we cannot assign to reference?
a) integer
b) floating
c) unsigned
d) null

Answer:d


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

Answer:c


3. Which refrence modifier is used to define reference variable?
a) &
b) $
c) #
d) none of the mentioned

Answer:a


4. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     void swap(int &a, int &b);
  4.     int main()
  5.     {
  6.         int a = 5, b = 10;
  7.         swap(a, b);
  8.         cout << "In main " << a << b;
  9.         return 0;
  10.     }
  11.     void swap(int &a, int &b)
  12.     {
  13.         int temp;
  14.         temp = a;
  15.         a = b;
  16.         b = temp;
  17.         cout << "In swap " << a << b;
  18.     }
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

Answer:a


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

Answer:b


6. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 9;
  6.         int & aref = a;
  7.         a++;
  8.         cout << "The value of a is " << aref;
  9.         return 0;
  10.     }
a) 9
b) 10
c) error
d) 11

Answer:b


7. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     void print (char * a)
  4.     {
  5.         cout << a << endl;
  6.     }
  7.     int main ()
  8.     {
  9.         const char * a = "Hello world";
  10.         print(const_cast<char *> (a) );
  11.         return 0;
  12.     }
a) Hello world
b) Hello
c) world
d) compile time error

Answer:a


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

Answer:a
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !