References in C++

Last Updated :
Discuss
Comments

Question 1

What is a reference in C++?

  • A pointer to a pointer

  • An alias for another variable

  • A copy of a variable

  • A memory address

Question 2

Which symbol is used to declare a reference in C++?

  • *

  • &

  • #

  • @

Question 3

Can a reference be reassigned to refer to another variable after initialization?

  • Yes

  • No

Question 4

What happens if you do not initialize a reference variable?

  • It will point to garbage

  • It will refer to NULL

  • Compilation error

  • It will be initialized to 0

Question 5

Which of the following is a valid reference declaration?

  • int &ref = x;

  • int ref = &x;

  • int *ref = x;

  • int ref =*x;

Question 6

What is the main use of references in function parameters?

  • To increase program size

  • To create copies

  • To allow functions to modify original values of arguments

  • To restrict changes to arguments

Question 7

What is the default behavior when passing arguments to functions in C++?

  • By Reference

  • By Pointer

  • By Value

  • By Address

Question 8

Which is not a valid usage of reference?

  • Function argument

  • Function return type

  • Member of an array

  • Class data member

Question 9

What is the difference between a reference and a pointer?

  • References can be NULL

  • Pointers cannot be reassigned

  • References cannot be reassigned

  • Pointers are faster

Question 10

What is the output?

C++
int a = 10;
int &b = a;
b = 20;
cout << a;


  • 10

  • 20

  • 0

  • Erropr

Tags:

There are 16 questions to complete.

Take a part in the ongoing discussion