C Programming Interview Questions


Answer. auto, register, static, extern.

Answer. Scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped.

Answer. To get address of a variable; For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables.;To pass large structures so that complete copy of the structure can be avoided.; To implement “linked” data structures like linked lists and binary trees.

Answer. NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize pointers as NULL if we don’t know their value at the time of declaration. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program

Answer. Dangling Pointer is a pointer that doesn’t point to a valid memory location. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.

Answer. A local static variable is a variable whose lifetime doesn’t end with a function call where it is declared. It extends for the lifetime of complete program. All calls to the function share the same copy of local static variables. Static variables can be used to count the number of times a function is called. Also, static variables get the default value as 0.

Answer. By default every local variable of the function is automatic (auto).

Answer. If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in “ “, then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path.

Answer. This function works exactly similar to malloc( ) function except for the fact that it needs two arguments as against one argument required by malloc( ).

Answer. The free( ) function is used to de-allocate the previously allocated memory using malloc( ) or calloc( ) functions.

Answer. This function is used to resize the size of memory block, which is already allocated. It found use of in two situations :

  • If the allocated memory block is insufficient for current application.
  • If the allocated memory is much more than what is required by the current application.

Answer. Recursion is one of the most powerful tools in a programming language, but one of the most threatening topics-as most of the beginners and not surprising to even experienced students feel.

Answer. There are two types of Recursion

  • Direct recursion.
  • Indirect recursion.

Answer. An array is a data structure used to process multiple elements with the same data type when a number of such elements are known.

Answer. A one-dimensional array is one in which only one subscript specification is needed to specify a particular element of the array.

Answer. Two dimensional arrays are also called table or matrix, two dimensional arrays have two subscripts. Two dimensional array in which elements are stored column by column is called as column major matrix.

Answer. Strings in C are stored as null character, '', terminated character arrays.

Answer. An array of strings is just a two dimensional array of characters.

Answer. Prints the formatted output onto the character array.

Answer. The starting address of the array is called as the base address of the array.

Answer. It is used to alias the existing type. Also used to simplify the complex declaration of the type.

Answer. The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.

Answer. Yes, it can be but cannot be executed, as the execution requires main() function definition.

Answer. Every local variable by default being an auto variable is stored in stack memory.

Answer. A structure containing the same structure pointer variable as its element is called as self-referential structure.

Answer. A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

Answer. Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

Answer.Can be used to input integer in all the supported format.

Answer. Yes, if it is not appearing as the last case and if we do not want the control to flow to the following case after default if any.

Answer. The arguments which we pass to the main() function while executing the program are called as command line arguments. The parameters are always strings held in the second argument (below in args) of the function which is array of character pointers. First argument represents the count of arguments (below in count) and updated automatically by operating system.

Answer. On failure fopen() returns NULL, otherwise opened successfully.

Answer. Linker generates the executable file.

Answer. By default the functions are called by value.

Answer. A pointer which is not allowed to be altered to hold another address after it is holding one.

Answer. There is no such. We need to compare element by element of the structure variables.

Answer. In first place they are non-standard keywords. A near pointer can access only 2^15 memory space and far pointer can access 2^32 memory space. Both the keywords are implementation specific and are non-standard.

Answer.Both functions are to retrieve absolute value. abs() is for integer values and fabs() is for floating type numbers. Prototype for abs() is under the library file < stdlib.h > and fabs() is under < math.h >.

Answer. Uninitialized pointers in the C code are known as Wild Pointers. These are a point to some arbitrary memory location and can cause bad program behavior or program crash.

Answer. ‘++a” is called prefixed increment and the increment will happen first on a variable. ‘a++’ is called postfix increment and the increment happens after the value of a variable used for the operations.

Answer. Prototype function is a declaration of a function with the following information to the compiler-Name of the function.,The return type of the function.,Parameters list of the function.

Answer. A pointer variable that contains the address of another pointer variable is called pointer on a pointer. This concept de-refers twice to point to the data held by a pointer variable.

Answer. The command rand() is available to use for this purpose. The function returns any integer number beginning from zero(0).