X

Important C Programming interview questions and answers

We are listing here Top 20 most important C programming question and answers. These are the most commonly asked C interview questions faced by freshers and experienced.

1. What is the recursive function? it’s advantages?

The function which calls itself is called a recursive function. A condition must be specified to stop recursion; otherwise, it will lead to an infinite process.
Advantages:
1. It Reduces unnecessary calling of function.
2. Recursion can make more readable and efficient algorithm descriptions.
3. Complex case analysis and nested loops can be avoided.

2. What is pointer? What are the advantages of pointer in C?

A pointer is a variable and it stores the address of another variable.
Advantages of pointer-
1. Use of the pointer makes the program execution faster.
2. By using pointers, arrays and structures can be handled in a more efficient way.
3.Without pointers, it will be impossible to create complex data structures such as linked list, trees, and graphs.
4. It makes possible to return more than one value from the function.

3. What is dangling pointer?

A pointer pointing to a memory location that has been deleted or freed is called a dangling pointer.

4. What is wild pointer?

Uninitialized pointers are known as wild pointers because they point to some random memory location and may cause a program to crash or behave badly.

5. What is NULL pointer?

NULL Pointer is a pointer which is pointing to nothing.

6. What is dereferencing in pointer?

Dereferencing a pointer means using the * operator (asterisk character) to access the value stored at a pointer. Dereferencing Operation is performed to access or manipulate data contained in a memory location pointed by a pointer.

7. What is pointer to pointer?

Here, the first pointer is used to store the address of the second pointer, which points the location that contains the actual value. they are also known as double pointers.
Declaration
Int  **pt ;

8. What is the difference between structure and union?

Structure and union both are user defined data types which contains variables of different data types.  Some of the key differences are:

  • In a structure, members do not share memory while in a union members share the memory space.
  • Any member can be retrieved at any time in a structure. Only one member can be accessed at a time in a union.
  • Several members of a structure can be initialized at once. Only the first member of a union can be initialized
  • Size of the structure is equal to the sum of the size of each member. Size of the union is equal to the size of the largest member
  • In structure altering the value of one member will not affect the value of another. While in union change in the value of one member will affect other member values.
9. What is the difference between static and dynamic memory allocation?
  • Static memory allocation is done at compile time but dynamic memory allocation is done at runtime using calloc(), malloc() and friends.
  • Memory reusability is not possible in static memory allocation whereas memory can be freed when not required in dynamic allocation.
  • In a static allocation, Memory cannot be resized after the initial allocation. In dynamic allocation, Memory can be dynamically expanded and shrunk as necessary.
10. Difference between ‘for’ loop and ‘do … while’ loop?

For loop: If the condition is not true first time than control will never enter in a loop. It is known as the entry controlled loop.
Do … while loop: Even if the condition is not true for the first time the control will enter in a loop at least once. It is known as an exit controlled loop.

11. What is the difference between malloc() and calloc()?

Both malloc() and calloc() are used in C language for dynamic memory allocation they obtain blocks of memory dynamically.
Differences:
1. The malloc() takes a single argument i.e, the number of bytes. Calloc() takes two arguments i.e, number of blocks and size of each block.
2. malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

12.Explain actual and formal parameters?

Actual parameter: parameters which are mentioned in the function call is known as the actual argument or parameter.
func1( a, b); here a and b are actual arguments.
Formal parameters: Parameters which are mentioned in the definition of the function is called formal arguments. These are very similar to local variables inside the function. Just like local variables, formal parameters are destroyed when the function ends.
int sum( j, k )
{ //logic
}
Here, j and k are formal parameters.

13. What is call by value and call by reference?

Call by value: In call by value, the value of the actual parameter is passed to a formal parameter of the called function and any change made to the formal parameter in the called function have no effect on the values of the actual parameter in the calling function.
Call by reference: the location of the actual parameter is passed to the formal parameter of the called function. This means by accessing the addresses of the actual parameter we can alter them within from the called function.

14. What is the difference between function declaration and function definition?

Function declaration: function declaration declares the name of the function and the return type. you are specifying that the following variable or function will be used in your program
int add();
Function definition A function definition provides the actual code structure of the function and determines what function does.
int add()
{
int a,b,sum;
a=3;b=4;
sum = a+b;
return sum;
}

15. Difference between ++a and a++?

++a is a prefix increment. It will increment the value of ‘a’ and return the incremented value
a++ is a postfix increment. It will increment the value of ‘a’ but return the original value before being incremented.

16. What is storage class specifiers and the types storage class specifiers in C?

Storage class specifiers in C language tells the compiler where to store a variable, how to store the variable, what is the initial value of the variable and lifetime of the variable.
There are 4 type of storage class specifiers
auto, register, static, extern

17. Describe modifiers in C?

Modifiers are keywords in c which changes the meaning of basic data type so that it more precisely fits the needs of various situations. Modifiers are prefixed with basic data types to modify the memory allocated for a variable.
There are five data type modifiers in C Programming Language:
long
short
signed
unsigned
long long

18. Define nested loop?

A loop inside another loop is called a nested loop.

19. Difference between array and pointer?

An array is the collection of the elements of the same data type.
The pointer is a variable that holds the memory address of another variable. 

20. Difference between exit() and return?

exit() is a system call which terminates the current process.
return() is a C language instruction/statement and it returns from the current function 

Categories: Interview
admin:

This website uses cookies.