C Language Interview Questions VOL-I

Q.1  What is recursion?

Ans:  A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.


 

Q.2  Difference between arrays and pointers?

Ans:  - Pointers are used to manipulate data using the address. Pointers use * operator to access the data pointed to by them
- Arrays use subscripted variables to access and manipulate data. Array variables can be equivalently written using pointer expression.

 

Q.3  Difference between pass by reference and pass by value?

Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable directly.Pass by value gives a copy of the value to the callee. This allows the callee to modify the value without modifying the variable. (In other words, the callee simply cannot modify the variable, since it lacks a reference to it.)

 

Q.4  Define a class?

Ans:  A class represents description of objects that share same attributes and actions. It defines the characteristics of the objects such as attributes and actions or behaviors. It is the blue print that describes objects.

 

Q.5 Difference between arrays and linked list?

Ans:  An array is a repeated pattern of variables in contiguous storage. A linked list is a set of structures scattered through memory, held together by pointers in each element that point to the next element. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer. With a linked list, there is a “next” pointer in each structure which says what element comes next.

 

Q.6  What are register variables? What are the advantages of using register variables?

Ans:  If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables
are declared as register variable as it’s access time is faster.

 

Q.7  Out of fgets() and gets() which function is safe to use and why?

Ans:  fgets() is safer than gets(), because we can specify a maximum input length. Neither one is completely safe, because the compiler can’t prove that programmer won’t overflow the buffer he pass to fgets ().

 

Q.8  What is the difference between a string copy (strcpy) and a memory copy (memcpy)?

Ans:  The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved.On the other hand, the memcpy() function is designed to work with any type of data. Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination.

 

Q.9  In printf() Function- What is the difference between "printf(...)" and "sprintf(...)"?

Ans:  sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.

 

Q.10  Difference between strdup and strcpy?

Ans:  Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using 
malloc().Unlike strcpy(), strdup() is not specified by ANSI .

 

Q.11  What is meant by file opening?

Ans:  The action of connecting a program to a file is called opening of a file. This requires creating an I/O stream before reading or writing the data.

 

Q.12  What is “this”s pointer?

Ans:  The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.

 

Q.13  Differentiate between for loop and a while loop? What are it uses?

Ans:  For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.

 

Q.14  What is the purpose of ftell ?

Ans:  The function ftell() is used to get the current file represented by the file pointer. ftell(fp);returns a long integer value representing the current file position of the file pointed by the
file pointer fp.If an error occurs ,-1 is returned.

 

Q.15  What does static variable mean?

Ans:  Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.


 

Q.16  What is multiple inheritance?

Ans:  A class can inherit properties from more than one class which is known as multiple inheritance.

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