Interview questions and answers for C language

Last Updated: Aug 23, 2013

Jan 10 • Resources • 37827 Views • 55 Comments on Interview questions and answers for C language

List of Interview questions and answers for C language : 

The C programming language is mother of all programming languages. It is very simple and easy to learn.In interview there are lots of question asked from this domain so prepration of the topic is very much important.We have prepared a list of 10 questions which is very important and can be asked in any interview.

1. What is C Language ?

Ans – 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.

interview question on c

Important c questions

2. What does static variable mean ?

Ans – 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.

3. What is the difference between calloc() and malloc() ?

Ans – 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 is a NULL pointer ?

Ans – 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 :

  1. Integer pointer : int *ptr=(char *);
  2. Float Pointer : float *ptr=(float *);
  3. Character Pointer : char *ptr=(char *);

5. Advantages of a macro over a function ?

Ans – 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 page thrashing ?

Ans – It happens when a high level of paging activity happen. Thrashing is caused by under allocation of minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multiprogramming. This problem can be eliminated by reducing the level of multiprogramming.

7. How do you override a defined macro?

Ans – You can use the #undef preprocessor directive to undefine (override) a previously defined macro. A way of overriding  macro is shown below.
#ifdef MACRO
#undef MACRO
#endif
#define MACRO X

8. What are the different storage classes in C ?

Ans – C has three types of storage classes: automatic, static and allocated.

  1. Variable having block scope and without static specifier have automatic storage duration.
  2. Variables with block scope, and with static specifier have static scope.
  3. Global variables (i.e, file scope) with or without the static specifier also have static scope.Memory obtained from calls to malloc(), alloc() or realloc() belongs to storage class.

9. When does the compiler not implicitly generate the address of the first element of an array?

Ans – 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.

10. Is using exit() the same as using return ?

Ans – No, The exit() function is used to exit from your program and return control to the operating system. The return statement is used to return from a function and return control to the calling function. If you issue a return from the main() function, you are essentially returning control to the calling function, which is the operating system. In this case, the return statement and exit() function are similar.

For any feedback / query please leave  a comment.

You may also like to go through :

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published. Required fields are marked *

55 Responses to Interview questions and answers for C language

  1. A. Preethi says:

    B. Tech first year

  2. A. Preethi says:
  3. Anonymous says:
  4. eeeee says:

    Cprogeam

« »