The Top Seven C Interview Questions in IT Interviews

Here I will Post some of the c programming interview questions which are frequently asked in every IT Interview, Use and suggest me for better posts like this

Ques 1: - Explain the use of this pointer ?

Ans: - The this keyword is used to represent an object that invokes the member function. It points to the object for which this function was called. It is automatically passed to a member function when it is called. e.g. when you call A.func(), this will be set to the address of A.

Ques 2: - Explain what happens when a pointer is deleted twice ?

Ans: - If you delete a pointer and set it to NULL, it it possibly cannot have an adverse effect. It is safe. However, if a pointer is deleted an not nullified, then it can cause a trap.

Ques 3: - Explain how to call C functions from C++?

Ans: - The extern keyword is used to call C functions from C++


extern "C" void showme()

Ques 3: - What is reference variable in C++?

Ans: - A reference variable is just like pointer with few differences. It is declared using & operator. A reference variable must always be initialized. The reference variable once defined to refer to a variable can’t be changed to point to other variable. You can't create an array of references the way it is possible with pointer.

Ques 4: - When should we use container classes instead of arrays ?

Ans: -It is advisable to use container classes of the STL so that you don’t have to go through the pain of writing the entire code for handling collisions, making sure its working well, testing it repeatedly with an overhead of time consumption.

Suppose you have some data that has values associated with strings and its fields consist of grades> in this situation you can directly use hash table instead of having it created by yourse

Ques 5: - Explain passing objects by reference, passing objects by value and passing objects by pointer.

Ans: -Passbyvalue:
The callee function receives a set of values that are to be received by the parameters. All these copies of values have local scope, i.e., they can be accessed only by the callee function. The simplicity and guarantee of unchanging of values passed are the advantages of pass by value.
Passbyreference:
The callee function receives a set of references which are aliases to

variables. If a change is made to the reference variable, the original value (passed by the caller function) will also be changed. All the references are handled by the pointers. Multiple values modification can be done by passing multiple variables.
Passbypointer:The callee function receives a pointer to the variable. The value of the pointer in the caller function can then be modified. The advantages of this process are that the changes are passed back to the caller function and multiple variables can be changed.

Ques 7: -What is NULL pointer and void pointer and what is their use ?

Ans: - A NULL pointer has a fixed reserved value that is not zero or space, which indicates that no object is referred. NULL pointers are used in C and C++ as compile-time constant. NULL pointer represents certain conditions, like successor to the last element in linked list, while a consistent structure of the list of nodes are maintained.
A void pointer is a special pointer that points to an unspecified object. A null pointer can not be dereferenced. The address manipulation can directly be done by pointer casting to and from an integral type of sufficient size.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post