SSC IMD SA Mock 02 – Question 192

Question:

In C++, what is a ‘vptr’ (virtual table pointer)?
C++ में ‘vptr’ (वर्चुअल टेबल पॉइंटर) क्या है?

Options:

  • A hidden pointer added by the compiler to an object of a class with virtual functions, pointing to that class’s vtable
  • A pointer to the base class constructor
  • A pointer to dynamically allocated heap memory
  • A pointer used exclusively for template instantiation
  • वर्चुअल फ़ंक्शंस वाली क्लास के ऑब्जेक्ट में कंपाइलर द्वारा जोड़ा गया एक छिपा हुआ पॉइंटर, जो उस क्लास के vtable को इंगित करता है
  • बेस क्लास कंस्ट्रक्टर का पॉइंटर
  • हीप मेमोरी का पॉइंटर
  • टेम्पलेट इंस्टेंटिएशन पॉइंटर

Correct Answer: a)

Explanation:

When a class contains or inherits virtual functions, the compiler inserts a hidden pointer member (vptr) pointing to the class’s Virtual Method Table (vtable) containing function pointers for runtime dynamic dispatch.
vptr कंपाइलर द्वारा ऑब्जेक्ट में डाला गया पॉइंटर होता है जो रनटाइम पर सही वर्चुअल फ़ंक्शन को कॉल करने के लिए vtable की ओर इंगित करता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top