Which of the following statements are True? A. The ++ operator can be overloaded to perform decrementation of a variable. B. It is necessary that a constructor in a class should always be public. C. Size of an object is equal to sum of sizes of data members and member functions within the class. D. A static data member is useful when all objects of a class are to share a common item of information. E. The this pointer always contains the address of the object using which the member function is being called. Choose the correct answer from the options given below:
This solution analyzes the truthfulness of five statements regarding C++ programming concepts to identify the correct combination.
True. C++ supports operator overloading, allowing developers to redefine the behavior of operators for user-defined types. While the $++$ operator is conventionally used for incrementing, it is syntactically possible to overload it to perform a decrementation operation. However, this is highly discouraged as it violates standard conventions and makes code confusing.
False. Constructors do not necessarily need to be public. They can be declared as $private$ or $protected$. Private constructors are often used in implementing design patterns like the Singleton pattern, restricting instantiation to within the class itself.
False. The size of an object is determined by the storage required for its non-static data members. Member functions typically do not occupy space within each object; they exist in the code segment and are shared among all objects of the class. Compiler padding for alignment can also affect the total size.
True. A $static$ data member is associated with the class itself, not with individual objects. All objects of the class share a single copy of the static data member. This is precisely its purpose: to store information common to all instances of the class, such as a counter for the number of objects created or shared configuration settings.
True. Within any non-static member function of a class, the implicit pointer named $this$ holds the memory address of the object through which the member function was called. It allows the member function to refer to the specific object's members.
Statements A, D, and E are identified as true based on C++ language rules and common practices.
Therefore, the correct option includes statements A, D, and E.
Let A be the base class in C++ and B be the derived class from A with protected inheritance. Which of the following statement is false for class B?
Which of the following statements are true regarding C++?
(a) Overloading a function gives the capability to an existing operator to operate on other data types.
(b) Inheritance in object-oriented programming provides support to reusability.
(c) When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.
(d) Overloading is a type of polymorphism.
Choose the correct option from those given below:Match List I with List II
| List I | List II | ||
| (Programming Paradigm) | (Characteristic) | ||
| A. | Imperative | I. | Declarative, clausal representation, theorem proving |
| B. | Object‐oriented | II. | Side‐effect free, declarative, expression evaluation |
| C. | Logic | III. | Imperative, abstract data type |
| D. | Functional | IV. | Command‐based, procedural |
Choose the correct answer from the options given below :
A member function can always access the data in _______, (in C++).
Which of the following is not correct for virtual function in C++?