C Programming Interview Questions And Answers 2021

Q1. What are the key features of C programming language? 

Answer:    

  • C is a platform-dependent language. 
  •  C offers the possibility to break down a large program into small modules.  
  • Also, the possibility of a programmer to control the language.  
  • C comes with support for system programming and hence it compiles and executes with high speed when compared to other high-level languages. 

 

Q2. What is the use of header files in C? 

Answer : Header files contain the definitions and set of rules of the functions being used in the programs. For example, when you use printf() or scanf() in your program, you nee to include stdio.h library function. Else your compiler will show an error. This is because, the standard input and output functions printf() and scanf() are stored in this header file. So similarly every header file stores a set of predefined functions which makes it easy to program. 

 

Q3 What happens if a headerfile is included twice? (tricky question) 

Answer :When the preprocessor sees a #include, it replaces the #include with the contents of the specified header. By using include guard(#), you can prevent a header file from being included multiple times during the compilation process. So basically, if a header file with proper syntax is included twice, the second one gets ignored. 

 

Q4 What is the difference between static & global variables? 

Global variables are variables which are defined outside the function. The scope of global variables begins at the point where they are defined and lasts till the end of the file/program. Whereas, static global variables are private to the source file where they are defined and do not conflict with other variables in other source files which would have the same name. 

Q5 What is Memory Leak in C? 

Answer :A memory leak occurs when programmers create a memory in the heap and forget to delete it. It decreases the efficiency of the performance of the system. 

Q6 What is Static and Dynamic memory allocation? 

  • Static memory allocation happens atcompile-time, and memory can’t be increased while executing the program.  
  • Whereas in case of dynamic memory allocation, this happens at runtime and memory can be increased while executing the program.  
  • Static memory allocation is used in arrays & dynamic memory allocation is used in Linked Lists. 

Static memory allocation uses more memory space to store a variable. 

Q9  What is the difference between ++a and a++? 

Answer : ‘++a’ is called prefix increment. First, the value stored in the variable ‘a’ gets incremented and then gets assigned to the same variable.  Whereas, ‘a++’ is called postfix increment. The value stored in the variable ‘a’ gets incremented after the execution of the particular line. 

Q10 What is the difference between while (0) and while (1)? 

Answer : While(1) is an infinite loop which will run till a break statement occurs. Similarly, while(2), while(3), while(255) etc will all give infinite loops only. 

Whereas, While(0) does the exact opposite of this. When while(0) is used, it means the conditions will always be false. Thus, as a result, the program will never get executed.  

Q11 What are different storage class specifiers in C?
Answer : auto, register, static, extern 

 

Q12 What is scope of a variable? How are variables scoped in C?
Answer : 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. 

 

Q13 What is NULL pointer?
Ans: 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. 

 

Q14 What is Dangling pointer?
Ans: 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. 

 

Q15 What are reserved words with a programming language? 

Ans) The words that are part of the slandered C language library are called reserved words. Those reserved words have special meaning and it is not possible to use them for any activity other than its intended functionality. 

Example void, return int. 

 

16) What is the explanation for the dangling pointer in C? 

Ans) When there is a pointer pointing to a memory address of any variable, but after some time the variable was deleted from the memory location while keeping the pointer pointing to that location. 

 

17) Describe static function with its usage? 

Ans) A function, which has a function definition prefixed with a static keyword is defined as a static function. The static function should call within the same source code. 

 

18) What is the difference between abs() and fabs() functions? 

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

 

19) Describe Wild Pointers in C? 

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

 

20) Describe the difference between = and == symbols in C programming? 

Answer ‘==’ is the comparison operator which is used to compare the value or expression on the left-hand side with the value or expression on the right-hand side. 

‘=’ is the assignment operator which is used to assign the value of the right-hand side to the variable on the left-hand side. 

 

Q 21 What is the explanation for prototype function in C? 

Answer  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. 

In this example Name of the function is Sum, the return type is integer data type and it accepts two integer parameters. 

 

22 What is the explanation for the cyclic nature of data types in C? 

Answer Some of the data types in C have special characteristic nature when a developer assigns value beyond the range of the data type. There will be no compiler error and the value change according to a cyclic order. This is called cyclic nature and char, int, long int data types have this property. Further float, double and long double data types do not have this property. 

This is called cyclic nature and char, int, long int data types have this property. Further float, double and long double data types do not have this property. 

 

23 Describe the header file and its usage in C programming? 

Answer The file contains the definitions and prototypes of the functions being used in the program are called a header file. It is also known as a library file. 

Example– The header file contains commands like printf and scanf is the stdio.h. 

 

24 There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affects when debugging? 

Answer : This concept called commenting out and is the way to isolate some part of the code which scans possible reason for the error. Also, this concept helps to save time because if the code is not the reason for the issue it can simply uncomment. 

 

Q25 What is a pointer on a pointer in C programming language? 

AnswerA 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. 

 

Q 26) What are the valid places to have keyword “Break”? 

Answer The purpose of the Break keyword is to bring the control out of the code block which is executing. It can appear only in Looping or switch statements. 

 

27 What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)? 

AnswerWhen the Header file includes within double quotes (“”), compiler search first in the working directory for the particular header file. If not found then in the built-in the include path. But when the Header file includes within angular braces (<>), the compiler only searches in the working directory for the particular header file. 

 

Q2What is a sequential access file? 

Answer In general programs store data into files and retrieve existing data from files. With the sequential access file such data saved in a sequential pattern. When retrieving data from such files each data needs to read one by one until the required information found. 

 

Q 29) What is the method to save data in a stack data structure type? 

Answer Data is stored in Stack data structure type using First in Last out (FILO) mechanism. Only top of the stack is accessible at a given instance. Storing mechanism is referred to as a PUSH and retrieve is referred as a POP. 

 

Q 30) What is the significance of C program algorithms? 

Answer The algorithm needs to create first and it contains step by step guidelines on how the solution should create. Also, it contains the steps to consider and the required calculations/operations within the program. 

 

Q31. Is it possible to use curly brackets ({}) to enclose a single line code in C program? 

Answer Yes, it is working without any error. Some programmers like to use this to organize the code. But the main purpose of curly brackets is to group several lines of codes. 

 

32) Describe the modifier in C? 

Answer Modifier is a prefix to the basic data type which is used to indicate the modification for storage space allocation to a variable. 

Example– In 32-bit processor storage space for the int data type is 4.When we use it with modifier the storage space change as follows. 

  • Long int -> Storage space is 8 bit 
  • Short int -> Storage space is 2 bit 

 

33) What are the modifiers available in C programming language? 

Answer There are 5 modifiers available in C programming language as follows. 

  • Short 
  • Long 
  • Signed 
  • Unsigned 
  • long long 

 

Q34 What is C language? 

Answer :is a mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation.  

 

Q35 Why is C known as a mother language? 

Answer : C is known as a mother language because most of the compilers and JVMs are written in C language. Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages.  

 

Q36 Why is C called a mid-level programming language? 

Answer :C is called a mid-level programming language because it binds the low level and high -level programming language. We can use C language as a System programming to develop the operating system as well as an Application programming to generate menu driven customer driven billing system 

 

Q37 When was C language developed? 

Answer :C language was developed in 1972 at bell laboratories of AT&T.  

 

Q38 What is a pointer on pointer? 

Answer : It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable. 

 

Q39 Distinguish between malloc() & calloc() memory allocation. 

Answer : Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s 

. 

Q40. Differentiate between Actual Parameters and Formal Parameters. 

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

 

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

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

 

Q42  What do you mean by a Nested Structure? 

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

 

Q43. What is a C Token? 

Answer :Keywords, Constants, Special Symbols, Strings, Operators, Identifiers used in C program are referred to as C Tokens. 

 

Q44. What is Preprocessor? 

Answer : A Preprocessor Directive is considered as a built-in predefined function or macro that acts as a directive to the compiler and it gets executed before the actual C Program is executed. 

 

Q45. Why is C called the Mother of all Languages? 

Answer : C introduced many core concepts and data structures like arrays,lists, functions, strings, etc. Many languages designed after C are designed on the basis of C Language. Hence, it is considered as the mother of all languages. 

 

Q44. What is an array? 

Answer . The array is a simple data structure that stores multiple elements of the same datatype in a reserved and sequential manner. There are three types of arrays, namely, 

  • One Dimensional Array 
  • Two Dimensional Array 
  • Multi-Dimensional Array 

 

Q45. What is /0 character? 

Answer : The Symbol mentioned is called a Null Character. It is considered as the terminating character used in strings to notify the end of the string to the compiler. 

 

Q46. What is the main difference between the Compiler and the Interpreter? 

Answer : Compiler is used in C Language and it translates the complete code into the Machine Code in one shot. On the other hand, Interpreter is used in Java Programming Langauge and other high-end programming languages. It is designed to compile code in line by line fashion. 

 

Q47. Can I use int datatype to store 32768 value? 

Answer : No, Integer datatype will support the range between -32768 and 32767. Any value exceeding that will not be stored. We can either use float or long int. 

 

Q48. Where can we not use &(address operator in C)? 

Answer : We cannot use & on constants and on a variable which is declared using the register storage class. 

 

Q49. Can I create a customized Head File in C language? 

Answer : It is possible to create a new header file. Create a file with function prototypes that need to be used in the program. Include the file in the ‘#include’ section in its name. 

 

Q50 Explain the # pragma directive. 

Answer : The following points explain the Pragma Directive. 

This is a preprocessor directive that can be used to turn on or off certain features. It is of two types #pragma startup, #pragma exit and pragma warn. #pragma startup allows us to specify functions called upon program startup. #pragma exit allows us to specify functions called upon program exit. #pragma warn tells the computer to suppress any warning or not. 

 

 

 

Leave a Comment