Logo F2FInterview

C Interview Questions

Q   |   QA

Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)

Class can have a public method for specific data type conversions.

For example:

class Boo
  double value;
    Boo(int i )
    operator double() 
     return value;

Boo BooObject;

double i  = BooObject; // assigning object to variable i of type double. now conversion  operator gets called to assign the value.

malloc allocates memory for object in heap but doesn't invoke object's constructor to initiallize the object.

new allocates memory and also invokes constructor to initialize the object.

malloc() and free() do not support object semantics 
Does not construct and destruct objects 

string * ptr = (string *)(malloc (sizeof(string)))

Are not safe 
Does not calculate the size of the objects that it construct 
Returns a pointer to void 

int *p = (int *) (malloc(sizeof(int)));
int *p = new int;

Are not extensible 
new and delete can be overloaded in a class 

"delete" first calls the object's termination routine (i.e. its destructor) and then releases the space the object occupied on the heap memory. If an array of objects was created using new, then delete must be told that it is dealing with an array by preceding the name with an empty []:-

Int_t *my_ints = new Int_t[10];
delete []my_ints;

"operator new" works like malloc.

There is no way for the compiler to verify that the macro parameters are of compatible types. The macro is expanded without any special type checking.

If macro parameter has a postincremented variable ( like c++ ), the increment is performed two times.

Because macros are expanded by the preprocessor, compiler error messages will refer to the expanded macro, rather than the macro definition itself. Also, the macro will show up in expanded form during debugging.

For example


#define min(i, j) (i < j ? i : j)


template<class T> 
T min (T i, T j) 
     return i < j ? i : j;

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: