Paper Tayyari

Lecture 30: Reference Data Type

MCQs, short and long questions from lecture 30.Lecture 30 ki MCQs, short aur long sawal.

9 MCQs · 7 short questions · 9 MCQs from past papers9 MCQs · 7 short sawal · 9 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/9
– correctsahi
1.
★ Final term 2017 (paper 2)

A ______ is considered as a special type of pointer which contains address of a memory location.

  1. AFunction
  2. BStructure
  3. CReference
  4. DClass

A reference is an alias implemented like a constant pointer that is automatically dereferenced.

2.
★ Final term 2017 (paper 4)

Which of the following will be the correct function call for function prototype given below? int func (int &);

  1. Afunc(int num);
  2. Bfunc(&num);
  3. Cfunc(num);
  4. Dfunc(*num);

A reference parameter is passed the variable itself, so the call is func(num); &num would pass an int* and not compile.

3.
★ Final term solved MCQs (Moaaz & Asad)

If there is a symbol (& sign) used with the variable name followed by data type then it refers to _____ and if & is being used with variable name then it refers to _____.

  1. AAddress of variable, reference variable
  2. BReference variable, value of variable
  3. CReference variable, address of variable
  4. DAddress of variable, value of variable

In a declaration (int &r) & makes a reference; in an expression (&x) it takes the address.

4.
★ Final term solved MCQs (Moaaz & Asad)

We can do arithmetic with references like pointers.

  1. ATrue
  2. BFalse

A reference is an alias; arithmetic on it changes the referred value, not an address.

5.
★ Final term solved MCQs (Moaaz & Asad)

Which of the following function calling mechanism is true for the function prototype given below? float func(float &);

  1. ACall by value
  2. BCall by reference using pointer
  3. CCall by reference using reference variable
  4. DNone of the given options

float & declares a reference parameter.

6.
★ Final term solved MCQs (Moaaz & Asad)

In functions that return reference, use __________variables.

  1. ALocal
  2. BGlobal
  3. CGlobal or static
  4. DNone of the given option

Returning a reference to a local would dangle; global or static variables outlive the call.

7.
★ Solved MCQs collection

To avoid dangling reference, always return the reference of a local variable from a function.

  1. ATrue
  2. BFalse

Returning a reference to a local variable creates a dangling reference.

8.
★ Past paper collection

We cannot increment ____________.

  1. Apointers
  2. Barrays
  3. Creferences
  4. Dvariables

A reference is a fixed alias; ++ on it changes the referred variable, not the reference itself.

9.
★ Past paper collection

We can _____________references.

  1. Aincrement
  2. Bdecrement
  3. Creassign
  4. DNone of the given

A reference is bound once at initialization and cannot be reseated or moved.