C Language Interview Questions VOL-III

Q.1  Define Constructors?

Ans:  A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.


 Q.2  What is message passing?

Ans:  An object oriented program consists of a set of objects that communicate with each other. Message passing involves specifying the name of the object, the name of the function and the information to be sent.

 

Q.3  How do declare an array?

Ans:  We can declare an array by specify its data type, name and the number of elements the array holds between square brackets immediately following the array name.syntax : data_type array_name[size];

 

Q.4  What are the advantages of using array of pointers to string instead of an array of strings?

Ans:  Efficient use of memory.Easier to exchange the strings by moving their pointers while sorting.

 

Q.5  What is the difference between the functions memmove() and memcpy()?

Ans:  The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.

 

Q.6  Is it better to use a macro or a function?

Ans:  The answer depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. There is no overhead involved in using a macro like there is in placing a call to a function. However, macros are generally small and cannot handle large, complex coding constructs. A function is more suited for this type of situation.Additionally, macros are expanded inline, which means that the code is replicated for each occurrence of a macro. Your code therefore could be somewhat larger when you use macros than if you were to use functions.Thus, the choice between using a macro and using a function is one of deciding between the tradeoff of faster program speed versus smaller program size. Generally, you should use macros to replace small, repeatable code sections, and you should use functions for larger coding tasks that might require several lines of code.

 

Q.7  Give two use of bitwise and (&) operator?

Ans:  It can be used to check whether particular bit is set or not. Eg suppose we have a number 101. Now if we want to check whether its second bit is on or off. To know this we must simply do bitwise and operation on this number with 010. Since result is 0 therefore we can acknowledge that second bit is low in our case.It can be used to unset particular bit. Eg if you want to unset second LSB of any number then you must simply do bitwise operation between that number and …11111101.

 

Q.8  What the advantages of using Unions?

Ans:  When the C compiler is allocating memory for unions it will always reserve enough room for the largest member.

 

Q.9  What is conversion operator?

Ans:  You can define a member function of a class, called a conversion function, that converts from the type of its class to another specified type.

 

Q.10  What does the error ‘Null Pointer Assignment’ means and what causes this error?

Ans:  As null pointer points to nothing so accessing a uninitialized pointer or invalid location may cause an error.

 

Q.11  What is encapsulation?

Ans:  Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object’s operation from the rest of the application.

 

Q.12  What is dynamic binding?

Ans:  Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run time.It is associated with polymorphism and inheritance.

 

Q.13  What is generic pointer in C?

Ans:  In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer,conversions are applied automatically (implicit conversion).

 

Q.14  What is dynamic array?

Ans:  The dynamic array is an array data structure which can be resized during runtime which means elements can be added and removed.

 

Q.15  What is static identifier?

Ans:  A file-scope variable that is declared static is visible only to functions within that file. A
function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not “automatic” and thus retains its value across function invocations.

 

Q.16  What is the use of default constructor?

Ans:  A constructors that accepts no parameters is called the default constructor.If no user-defined constructor exists for a class A and one is needed, the compiler implicitly declares a default parameterless constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when the compiler uses this constructor to create an object of type A. The constructor will have no constructor initializer and a null body.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code