C Interview Questions and Answers



auto, register, static, extern
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.
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.
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
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.
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.
By default every local variable of the function is automatic (auto).
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.
Prints the formatted output onto the character array.
The starting address of the array is called as the base address of the array.
It is used to alias the existing type. Also used to simplify the complex declaration of the type.
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.
Yes, it can be but cannot be executed, as the execution requires main() function definition.
Every local variable by default being an auto variable is stored in stack memory.
A structure containing the same structure pointer variable as its element is called as self-referential structure.
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.
Can be used to input integer in all the supported format.
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.
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.
On failure fopen() returns NULL, otherwise opened successfully.
Linker generates the executable file.
By default the functions are called by value.
A pointer which is not allowed to be altered to hold another address after it is holding one.
There is no such. We need to compare element by element of the structure variables.
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.
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 >.
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.
‘++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.
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.
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.
The command rand() is available to use for this purpose. The function returns any integer number beginning from zero(0).





You may also like: