Languages [TCS Placement]: Sample Questions 112 - 114 of 131

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 112

Question

MCQ▾

Which of the following cannot be used with the keyword virtual?

Choices

Choice (4)

a.

Class

b.

Member functions

c.

Constructor

d.

Destructor

Answer

c.

Explanation

  • A constructor cannot be virtual.
  • Virtual keyword makes a virtual table to map function at run-time with help of Vptr (virtual pointer) .
  • Now this virtual pointer Vptr is the first 4 bytes of the object.
  • So if the constructor has been called then the Vptr has to be present in the object allocation- that means the constructor must already have been called

Question 113

Edit

Write in Short

Short Answer▾

Write the equivalent pointer expression for referring the same element a [i] [j] [k] [l] ?

Explanation

  1. a[i] == ⚹(a+i)
  2. a[i][j] == ⚹(⚹(a+i)+j)
  3. a[i][j][k] == ⚹(⚹(⚹(a+i)+j)+k)
  4. a[i][j][k][l] == ⚹(⚹(⚹(⚹(a+i)+j)+k)+l)

Question 114

Question

MCQ▾

Which of the following statement is correct?

Choices

Choice (4)

a.

A reference is stored on heap.

b.

A reference is stored in a queue.

c.

A reference is stored in a binary tree.

d.

A reference is stored on stack.

Answer

d.

Explanation

  • References are stored on stack because references just refer to any local variable- which is allocated on the stack.
  • So indirectly reference is stored in stack.
  • Example:
  1. #include<iostream>
  2. usingnamespacestd;
  3. classabc
  4. {
  5.     inta =0;
  6.     int &b =a;
  7.     int &c =b;
  8. };
  9. intmain()
  10. {
  11.     cout"size is "sizeof(classabc)≪endl;
  12. }
  • Output:

    Size is 24

  • So, it gets space in stack

Developed by: