References

6.Which of the following is NOT a valid reference initialization in C++?
  • A. int &a = 10;
  • B. const int &a = 10;
  • C. int &a = 10.5;
  • D. double &a = 10.5;

int &a = 10.5;

int &a = 10.5;

7.What is the difference between passing by reference and passing by value in C++?
  • A. Passing by reference creates a copy of the argument
  • B. Passing by reference passes the actual object to the function
  • C. Passing by reference is slower than passing by value
  • D. Passing by reference creates a new variable

Passing by reference passes the actual object to the function

Passing by reference passes the actual object to the function

8.What does the following C++ code do?
int a = 5; int &b = a; b++; cout << a;
  • A. It prints 6
  • B. It prints 5
  • C. It results in a segmentation fault
  • D. It prints an error message

It prints 6

It prints 6

9.Which of the following statements is true about references in C++?
  • A. A reference can be null
  • B. A reference must always be initialized
  • C. A reference can be reassigned to refer to a different variable after initialization
  • D. References cannot be passed as arguments to functions

A reference must always be initialized

A reference must always be initialized

10.Consider the following code:
void func(int &a) { a = 100; } int main() { int x = 10; func(x); cout << x; return 0; }
  • A. 10
  • B. 100
  • C. Compilation error
  • D. Runtime error

100

100