Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 13 - 14 of 354

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

Question 13

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What are the advantages of inheritance?

Explanation

  • The most frequent use of inheritance is for deriving classes using existing classes that provides reusability.
  • The existing classes remain unchanged.
  • With reusability, the development time of software is reduced.
  • Derived class extends the properties of base classes to generate more dominant objects.
  • The same base classes can used by a number of derived classes in class hierarchy.
  • When a class is derived from more than one class- every derived classes have similar properties to those of base classes- reusability.

Question 14

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     if (~0 == (unsignedint) -1)
  4. printf (“Youcananswerthisifyouknowhowvaluesarerepresentedinmemory”); }

Explanation

You can answer this if you know how values are represented in memory.

In this program

Table Shows the Program
if (~0 == (unsigned int) -1)
  • ~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer.
  • -1 is represented in unsigned value as all 1՚s and so both are equal.
printf ( “You can answer this if you know how values are represented in memory” ) ;
  • printf prints the “You can answer this if you know how values are represented in memory”

Developed by: