3i Infotech Papers: Sample Questions 301 - 302 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 301

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

  1. main ()
  2. {
  3.     extern out;
  4.     printf ( “%d” out);
  5. }
  6. int out = 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

    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 number: 302

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

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.