C Programming Job Interview Questions and Answers – Page 2

C Programming Job Interview Questions and Answers – Page 2
Love and Share

12. What are some of the difference between pointers and arrays?

Answers: Array is a collection of the similar data type. Array use sub-scripted variables to access and manipulate data. Array variables can be Equivalently written using pointer expression. Where as Pointers are used to manipulate data using the address. Pointers use an operator to access the data pointed to by them.

 In General, Array can allocate variables but cannot reallocate those variable if required.  Whereas the pointer was assigned to allocate variables and they can also relocate and also are re sizable.


13. What does static variable mean?

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


14. What is volatile variable?

Answers: Volatile variables are those variables which alter the default way of the program. The variable which does not change while compiling but are changeable during execution


15. Difference between global and static variable?

Answers: Static variables persist throughout the scope, but the lifespan is not throughout the program. Global variables persist throughout the scope of base blocks of memory that is their lifespan is throughout the program.


16. What is a structure?

Answers: Structure constitutes a super data type which represents several different data types in a single unit. A structure can be initialized if it is static or global.


17. What is the use of header file?

Answers: Header files provide the definitions and declarations for the library functions. It is a file with extension .h which contains C function declarations and macro definitions to be shared between several sources files.


18. What is the purpose of main() function?

Answers: In C, program execution starts from the main() function. Every C program must contain a main() function.  Like all C language functions first comes the function’s name, main, then comes a set of parentheses.

 So the purpose of the main() function is:

 – the main function is the starting point of the program. The first line of the code that the compiler compiles and start understanding the flow of the program.

 – tells the compiler, about an initial point from where the program starts.

 – It returns an int value to the environment that called the program.

 – Whenever you compile your code to an executable file, the compiler searches for main() function as an entry for your program by default.

 – Recursive call is allowed for main( )

 – Program execution ends when the closing brace of the function main( ) is reached.

 – it is a well-defined user defined function. Any user-defined name can also be used as parameters for main( ) instead of argc and argv


19. Where can the function pointers be used?

Answers: By definition, a function pointer is a variable that stores the address of a function. It can later be called anytime, to execute the function it points to.

One important use of function pointer is that it can be used when if/switch statements are present, in late binding(variation tables) and to implement call backs activities. So, Function pointers can be useful when you want to create callback mechanism and need to pass the address of a function to another function.

 It can also be used as Arguments to Other Functions or when you want to store an array of functions, to call dynamically

Love and Share