Commonly Asked C Programming Interview Questions and Answers

  • What is the difference between declaration and definition of a variable or function?

Declaration a variable and function will declare that there is a variable or function in the program but the memory allocation is not done.Generally extern keyword is used

Definition a variable or function will allocate required memory area. Normal definitions like int is used.

  • What are storage class specifiers in C like auto?

auto, reg,ster, static ,extern

  • What is scope of a variable in C?

Scope of a variable is the part of the applications where the variable can be directly accessible.

  • What is pointer in C?

Points memory areas where a variable or function is stored. Used for efficiency and practical solutions.

  • In which cases should  we use pointers in C?
    • Getting address of a variable
    • Getting address of a function
    • Pass large data like structures between functions
    • To implement linked data structures
    • Share local data with other functions and code parts
  • What is NULL pointer in C?

NULL pointer points nowhere. So it is used for pointer initialization to set empty pointer.

  • What is dangling pointer in C?

Dangling pointer is a pointer where it points invalid memory area. We can say that it is unworking pointer.

  • What is memory leak in C and how can we avoid?

Memory leaks is a situation where application memory area is flooded. Generally occurs when heap memory area is not deleted.

  • What are static variables in C? When we use them?

Static variables values are hold during the applications run time. We can preserve the value for long time

  • What are static functions in C? When we use them?
LEARN MORE  What Is C# Programming Language

Static function can only accesses by the file they were defined.

  • What is the difference between malloc and calloc in C?

Both allocated memory but calloc fills the allocated memory with .

  • What is difference between including header file with brackets <> and quotes “” in C?

<> will search header file in builtin paths

"" will search header file in builtin paths and current working directory

  • What is the association between arrays and pointers?

Array variable names hold address of the first element of the array. Where it acts like a pointer.

  • Why we use typedef?

Typedef is used to create alias or new name for already defined type.

  • What is call by value for functions in C?

While providing parameters to the function provided value is copied to the function parameter.

  • What is call by reference for functions in C?

While providing parameters to the function provided variable pointer is provided to the function parameter so there will be no copy.

  • What is the difference between call by value and reference for functions in C?

Call by value is easier to use but data is copied which cause some performance loss

Call by reference is a bit trickier but have performance gains and gives ability to access without any scope restriction.

Leave a Comment