Languages [3i Infotech Placement]: Sample Questions 349 - 350 of 546

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 349


Describe in Detail


What is the output of the following program?

  1. voidmain()
  2. {
  3.     void ⚹v;
  4.     intinteger=2;
  5.     int ⚹i=&integer;
  6.     v=i; printf("%d",(int⚹)⚹v);
  7. }


  • Compiler Error: invalid use of void expression
  • In the program
Table Shows the Program
void ⚹ v;
  • Define a void pointer v.
int integer = 2;
  • Define the int variable integer = 2.
int ⚹ i = &integer;
  • Int pointer i stores the address of integer variable
v = i;
  • Stores the pointer ‘i’ value in void pointer v.
  • But, void pointer is a generic pointer type.
  • No pointer arithmetic can be done on it.
  • Void pointers are normally used for,

    1. Passing generic pointers to functions and returning such pointers.

    2. As a intermediate pointer type.

    3. Used when the exact pointer type will be known at a later point of time.

  • So the answer is compiler error: we cannot apply indirection on type void ⚹ .

Question 350


Describe in Detail


What is inheritance?


Image Shows the Class
  • Deriving an object from an existing class is inheritance
  • Inheritance is the process of inheriting all the features from a class.
  • A class derived from another class is called a subclass, whereas the class from which a subclass is derived is called a superclass.
  • A subclass can have only one superclass, whereas a superclass may have one or more subclasses.
  • A subclass inherits the characteristics (properties and methods) of its superclass.
  • A vehicle is a superclass and a car is a subclass.
  • The car inherits all of the vehicle՚s properties.
  • The inheritance mechanism is very useful in code reuse.

Developed by: