Interview questions for C Programming

C Programming Interview Questions have become a crucial part of the interview process in almost all MNC companies. This article is mainly focused on the most asked and the latest updated questions that are appearing in most of the current interviews

1. What are the basic Datatypes supported in C Programming Language?

The Datatypes in C Language are broadly classified into 4 categories. They are as follows:
• Basic Datatypes
• Derived Datatypes
• Enumerated Datatypes
• Void Datatypes
The Basic Datatypes supported in C Language are as follows:
Datatype Name Datatype Size Datatype Range
short 1 byte -128 to 127
unsigned short 1 byte 0 to 255
char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
int 2 bytes -32,768 to 32,767
unsigned int 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
float 4 bytes 3.4E-38 to 3.4E+38
double 8 bytes 1.7E-308 to 1.7E+308
long double 10 bytes 3.4E-4932 to 1.1E+4932

2. What is the difference between declaration and definition of a variable/function?

Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them. But the declaration of a variable/function serves an important role. And that is the type of the variable/function. Therefore, when a variable is declared, the program knows the data type of that variable. In case of function declaration, the program knows what are the arguments to that functions, their data types, the order of arguments and the return type of the function. So that’s all about declaration

3. What do you mean by Dangling Pointer Variable in C Programming?

Ans: A Pointer in C Programming is used to point the memory location of an existing variable. In case if that particular variable is deleted and the Pointer is still pointing to the same memory location, then that particular pointer variable is called as a Dangling Pointer Variable.

4. What is scope of a variable? How are variables scoped in C?

Ans: 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. See this for more details.

5. What do you mean by the Scope of the variable? What is the scope of the variables in C?

Scope of the variable can be defined as the part of the code area where the variables declared in the program can be accessed directly. In C, all identifiers are lexically (or statically) scoped.

6. What are static variables and functions?

The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.

7. When should we use pointers in a C program?

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

8. What is NULL pointer?

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.

9. What is Dangling pointer?

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. Following are examples.

10. Differentiate Source Codes from Object Codes?

Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do. However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor. In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ

11. In C programming, how do you insert quote characters (‘ and “) into the output screen?

This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \’ (for single quote), and \” (for double quote).

12. Differentiate between calloc() and malloc()?

calloc() and malloc() are memory dynamic memory allocating functions. The only difference between them is that calloc() will load all the assigned memory locations with value 0 but malloc() will not.

13. What are the valid places where the programmer can apply Break Control Statement?

Break Control statement is valid to be used inside a loop and Switch control statements.

14. What are local static variables? What is their use?

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. For example, the following program prints “0 1”

15. How can we store a negative integer?

To store a negative integer, we need to follow the following steps. Calculate the two’s complement of the same positive integer.
Eg: 1011 (-5)
Step-1 − One’s complement of 5: 1010
Step-2 − Add 1 to above, giving 1011, which is -5

16. Differentiate between Actual Parameters and Formal Parameters?

The Parameters which are sent from main function to the subdivided function are called asActual Parameters and the parameters which are declared a the Subdivided function end are called as Formal Parameters.

17. Can a C program be compiled or executed in the absence of a main()?

The program will be compiled but will not be executed. To execute any C program, main() is required.

18. What do you mean by a Nested Structure?

When a data member of one structure is referred by the data member of another function, then the structure is called a Nested Structure.

19. What is the use of a ‘\0’ character?

It is referred to as a terminating null character, and is used primarily to show the end of a string value.

20. What is the difference between the = symbol and == symbol?

The = symbol is often used in mathematical operations. It is used to assign a value to a given variable. On the other hand, the == symbol, also known as “equal to” or “equivalent to”, is a relational operator that is used to compare two values.

21. What is the modulus operator?

The modulus operator outputs the remainder of a division. It makes use of the percentage (%) symbol. For example: 10 % 3 = 1, meaning when you divide 10 by 3, the remainder is 1.

leave your comment

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