C Programming - Interview Questions & Answers
1. What is C Language ?
C is a general purpose programming language and it was developed by Dennis Ritchie. Programs written in this language are the set of instructions given by a programmner to the computer in high level language. The program execution process consists of two processes , first it uses a compiler to translate the high level program into machine code then execute the instruction set.
2. What is storage class? What are the different storage classes in C?
A storage class in C is an attribute that tells us where the variable would be stored, what will be the initial value of the variable if no value is assigned to that variable, life time of the variable and scope of the variable.
The storage classes in c are auto, register, static, and extern.
3. What is the difference between calloc() and malloc() ?
A block of memory may be allocated using the function malloc malloc(). The malloc function reserves a block of memory of specified size and returns a pointer of type void(). This means we can assign the base address of the block to any type of pointer.
Syntax – P = (cast type*)malloc(byte size);
Calloc() is also a memory allocation function which is generally used to allocate memory for array and structure. malloc() is used to allocate a single block of storage space, calloc() allocates multiple blocks of storage, each of same size and initializes them with zero.
Syntax – P = (cast type*)calloc(n,array size);
4. What does static variable mean ?
Static variable is available to a C application, throughout the life time of the program. At the time of starting the program execution, static variables allocations takes place first. In a scenario where one variable is to be used by all the functions (which is accessed by main () function), then the variable need to be declared as static in a C program.
5. Advantages of a macro over a function ?
Actually macro and function are used for different purposes. A macro replaces its expression code physically in the code at the time of preprocessing. But in case of function the control goes to the function while executing the code. So when the code is small then it is better to use macro.But when code is large then function should be used.
6. What is an argument?
An argument is an entity used to pass data from the calling to a called function.
7. What is a NULL pointer ?
A NULL pointer is a pointer which is pointing to nothing. It just points the base address of the segment. It means that it will not point to other valid pointer, other variable, array cell or anything else. It will never be compared with anything.
Example :
Integer pointer : int *ptr=(char *);
Float Pointer : float *ptr=(float *);
Character Pointer : char *ptr=(char *);
8. When does the compiler not implicitly generate the address of the first element of an array?
Whenever an array name appears in an expression such as
array as an operand of the sizeof operator.
array as an operand of “&” operator.
array as a string literal initializer for a character array
Then the compiler does not implicitly generate the address of the address of the first element of an array.
9. What is a function?
A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.
10. What are built in functions?
The functions that are predefined and supplied along with the compiler are known as built-in functions. They are also known as library functions.
Related Links