3i Infotech Placement: Sample Questions 344 - 345 of 1245

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

Question 344

Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     externout;
  4.     printf ( “%d” out);
  5. }
  6. intout =100;

Explanation

  • In a program using external linkage
  • This means that the object or function is accessible through this name from other translation units in the program
    Table Showing the Program
    extern out;Here out is external object.
    printf ( “% d” out) ;Print the value of out
    int out = 100;Here out is external object integer and it՚s value is 100
  • So the answer is 100.

Question 345

Edit

Describe in Detail

Essay▾

Differentiate between a deep copy and a shallow copy?

Explanation

  • Shallow copy:-Shallow copy copies the contents of one object into another instance of the same class creating a mirror image. Due to copying of references and pointers, the two objects share the same externally contained contents. When one object is destroyed the pointers of other object become unpredictable.
  • Deep copy:-Deep copy the contents of one object to create another instance of the same class. In a deep copy, the target object will have its own buffers and resources thus the destruction of either object does not affect remaining object. The overloaded assignment operator would create a deep copy of objects.
  • Copy constructor simply copies the data values member by member. This method of copying is called shallow copy. For simple classes, comprised of built in types and no pointers this is acceptable.
  • If the object has any pointers a deep copy would allocate memory and copy elements pointed to by the pointers.
  • A deep copy is used for objects that are returned from a function.

Developed by: