Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 194 - 196 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 194

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is slicing?

Explanation

  • Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object. Explanation: Consider the following class declaration: class base {… base& operator = (const base&) ; base (const base&) ;} void fun () {base e = m; e = m;}
  • Base copy functions are not aware about the derived members, thus only the base part of the derived is copied. This is called slicing.
  • One reason to pass objects of classes in a hierarchy is to avoid slicing, other reason can be preserving polymorphic behavior and gaining efficiency.

Question 195

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is an orthogonal base class?

Explanation

  • If two base classes have no overlapping methods or data, they are said to be independent of, or orthogonal to each other.
  • Orthogonal means that two classes operate in different dimensions and do not interfere with each other in any way.
  • The same derived class may inherit such classes with no difficulty.
Given the Image is Orthogonal Bases Example

Question 196

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     int ⚹j;
  4.     {
  5.         inti =10;
  6.         j =&i;
  7.     }
  8.     printf ( “%d” ⚹j);
  9. }

Explanation

In the program

Table Shows the Program
int ⚹ j;Define the integer pointer j.
int i = 10;The variable i is a block level variable and the visibility is inside that block only.

However, the lifetime of i is lifetime of the function so it lives up to the exit of main function.

j = &i;The i is still allocated space
printf ( “% d” ⚹ j) ;⚹ j prints the value stored in i since j points to i.

Developed by: