C interview questions
1.Define C
Ans : C is a general Purpose, Procedure oriented Programming language created by Dennis Ritchie in 1970’s. It’s the mother of all high-level programming languages.
2. In C data types are divided into how many types ?
Ans : The data types in C are broadly divided into two types
1) Primitive Data Types: Floating Point, Integer, Double, Character
2) User Defined Data Types: Union, Structure, Enum and Typedef
3. Explain Ternary operator in C.
Ans : The ternary operator in C is a special operator which is short of using conditional statements
Syntax : testCondition ? Expression1: expression2;
If the condition is True then expression one is executed else the expression 2 is executed.
4. Need of pointers in C.
Ans : Pointers in C are used to implement dynamic memory allocation and also faster access of array elements using their id(address) directly instead of accessing them using their indices. They are indirectly going to save memory space by dynamically allocating space.
5. In C how many ways we can access the functions
Ans : There are two ways we can access the functions in C programming language.
1) Call By Reference : An address or id of the variable is passed as an argument to the function
2)Call by Value : the copy of the variable is passed as arguments to the function.
6. Use of Modifier in C
Ans : As the name indicates the modifiers in C are used to modify the value of a variables especially integer and character variables. Theya re going to specify the amount of space to be allocated to a variable. There are two types of modifiers in C Size Modifiers-short , long and Sign modifiers – signed and unsigned.
7. How to free memory that has allocated previously in C?
Ans : Free() is a method in C which is going to deallocate or free the memory.
8. Storage class specifiers in C.
Ans : In C there are four storage class specifiers
- auto – the default storage class for all variables inside a block in C. The stack is used as storage unit. The scope of these variables are within the block where they are declared. Initial value of extern variables is Garbage Value.
- extern – The scope of these type of variables is global. The main purpose of extern variable is to access they can be accessed between two or more files which are part of same program. The default value for these are zero(0)
- static – These have the capability to store the value even they are out their scope. The default value of static variables is zero(0).
- register – When one wants to sore the variables in the registers of the microprocessor directly then they re declared as register variables. The default value for these variables is Garbage Value
9. Difference between structure and Unions in C
Ans : Both structure and Union are user defined data types in C but the basic difference between them is union is much more efficient to use in terms of memory management because the memory occupied by structure is the sum of all the parameter’s size in C when it comes to Union the memory occupied by it the maximum parameters size
10. Difference between Macro and Function in C
Ans : The basic difference is that the Macros are defined using pre processor directives which means they are going to initialize or process the function even before it compiles but the functions are initialized only after compilation of the program.
11. DMA in C and explain how it can be achieved?
Ans : DMA stands for Dynamic Memory Allocation in C. The root of DMA implementation are pointers but actually the DMA is implemented through malloc()[ Memory Allocation ] and calloc() [ Contagious Allocation ] functions.
12. Difference between #include<> and #include ” “
Ans : #include<> is used to include pre-defined header files in the current c program whereas #include “ “ is used to include the user defined header files in c program.
13. is it possible to compile C program without main() function?
Ans : Yes we can compile the c program without main function by indirectly defining it as macro using pre processor directive as follows:
#include<stdio.h>
#define sample main
Void sample()
{
Printf(“Hello Curious Coders”);
}
14. Steps involved in c program compilation process
Ans : Mainly there are four steps involved in c program compilation process
-> Preprocessing – Removal of comments, inclusion of files done here
-> Compiling – Intermediate code is produced here
-> Assembling – Machine level code is produced here
-> Linking – Links all the function calls with their definitions in the program
15. Does null character occupies space in memory?
Ans : Yes, the null character occupies space in memory. The strings in C are ended with null character (‘\0’) so one byte of memory is occupied by the null character in memory during its initialization.