30 Basic C Interview Questions and Answers - MetaTutorials

MetaTutorials

The Tutor is Yours!

30 Basic C Interview Questions and Answers

Here, you will get important 30 Basic interview questions on C Programming in an easy language. This article provides the latest updated and repeatedly asked definitions & differences in the interviews of IT companies. 
These questions also help you to attempt the objective questions and the questions asked in the interviews.
 
Ques 1. What is C Language?
Ans. The C programming language is a simple, flexible, and structured programming language which was developed in 1972 by Dennis Ritchie at bell laboratories using the UNIX operating system.
This programming language is mainly used for developing desktop applications and operating systems. It also helps the programmers and developers for developing mobile operating systems. 
 
Ques 2. What are the features of the C programming language?
Ans. There are following some features or characteristics of the C programming language:
  • It is a simple programming language because it follows the structural design. 
  • C language is widely used in the Internet of Things (IoT) applications. 
  • It also allows developers to develop desktop and mobile operating systems.
  • It supports various predefined functions that make the fast development of applications and programs.
  • This language has the ability to extend itself. 
  • It provides the pointers, which allows users to directly interact with the memory.  

Ques 3. Why C is called the mother of all other languages?
Ans. C is called as mother language because most of the kernels and compilers are written in this language. 
And, most of the popular languages are designed with the help of the C programming language. That's why C is called the mother language

Ques 4. Why C language is called the middle-level language?
Ans. Because the developers use this language for developing system programming as well as application programming.
C language provides the features for both low-level language and high-level programming  language, that's why it is considered as middle-level level language. 

Ques 5. What is the difference between C and C++?
Ans. Following table describes the differences between C and C++ programming language:
C Programming Language       C++ Programming Language
1. C is a structural and procedural programming language.1. C++ is object-oriented programming. 
2. This language was introduced in 1972 by  Dennis Ritchie who was a great computer scientist. 2. This language was introduced in 1979 by Bjarne Stroustrup.  
3. The program of this language follows the top-down approach.3. The program of this language follows the bottom-up approach.
4. This programming language only supports the pointers.4. Whereas, this programming language supports the pointers as well as references.
5. C language does not allow its users to use the function overloading. 5. C++ language allows its users to use the function overloading because it is an OOPS concept. 
6. This programming language contains only 32 keywords. 6. This programming language contains 48 keywords. 
7. As it is a procedural programming language, so, the functions and data are separated from each other in C. 7. As it is an object programming language, so, the functions and data are combined in the object in C++. 
 8. This supports only built-in datatypes. 8. This supports built-in as well as predefined datatypes.

Ques 6. What is the purpose of scanf() and printf() in C language?
Ans. scanf() function is used for scanning the values entered by the user in the C program. On the other hand, the print() function is used for printing or displaying the value on the screen.  
Following are the four format specifiers used in printf() and scanf() function:
1. %d: It is an int type format specifier used for printing and scanning the integer values. 
2. %f: It is a float type format specifier used for printing and scanning the decimal values.  
3. %c: It is a char type format specifier used for printing and scanning the character values. 
4. %s: It is a string type format specifier used for printing and scanning the strings.

Ques 7. What is the difference between compiler and Interpreter?
Ans. Compiler: Compiler is a computer program which scans the entire code and translates the whole code into the machine code. 
It converts the high-level program into the computer understandable code before the execution of the program.
Error detection in the compiler is difficult.
C, C++, Java, C#, Scala are the programming languages which use the compiler. 

Translator: Translator is a computer program which translates only a single statement at a time. 
It converts the high-level program into the computer understandable code at the time of program execution. 
Error detection in the translator is easier as compared to the compiler.
Perl, PHP, Ruby are the programming languages which use the translator. 

Ques 8. What is the difference between assembler, compiler, and Interpreter?
Ans. Assembler: It is a computer program which converts low-level (assembly) language into machine understandable language. It contains the assembly language instructions for converting the low-level source code into code which is understandable by the computer. 
Compiler: It is a computer program which converts the whole source code written in a high-level language into the machine code. 
Interpreter: It is a computer program which converts the source code into the intermediate code and then each statement of intermediate code executes one by one.

Ques 9. What is the data type in C?
Ans. Data types in C programming language tell the C compiler what type of value is defined by the user in the variable. They also specify what type of value returned by the function. 

Ques 10. Enlist the basic data types supported by the C programming language?
Ans. Following are the four different types of basic data types in the C language:
  1. Int: This data type indicates the value is a number.
  2. Char: This data type indicates the value is character.
  3. Float: This data type indicates the double real number with single precision. 
  4. Double: This data type also indicates the real number but with double precision. 

Ques 11. Enlist the types of data type used in C language?
Ans. Names of four data type used in C programming language are as follows:
  1. Basic Data Type: (Int, Char, Float, Double) 
  2. Derived Data Type: (Array, Pointer, Structure, Union)
  3. Enumerated Data Type: (enum)
  4. Void Data Type: (void)

Ques 12. Enlist the Integer (int) data types with their size and range used in C language?
Ans. Following are the different Integer (int) data types used in C programming language:
Integer Type         Size        Range
 int  2 bytes  -32768 to 32767
 signed int;  2 bytes  -32768 to 32767
 unsigned int   2 bytes  0 to 65535
 short int  2 bytes  -32,767 to 32,767 
 signed short int  2 bytes  -32,767 to 32,767
 unsigned short int   2 bytes  0 to 65535
 long int     4 bytes  0 to 65,535
 signed long int 4 bytes   -2,147,483,648 to 2,147,483,647
 unsigned long int  4 bytes  0 to 4,294,967,295

Ques 13. Enlist the Float (float) data types with their size and range used in C language?
Ans. Following are the different Float (float) data types used in C programming language:
 Float Type     Size  Range
 float 4 bytes 1.2e-38 to 3.4e+38
 double 8 bytes 2.3e-308 to 1.7e+308
 long double 10 bytes 3.4e-4932 to 1.1e+4932

Ques 14. What is a variable in C?
Ans. Variable is nothing but a name given to the memory location that our C programs can manipulate. It is a term used for storing the integer, character, float, and string values which are given by the user. Its value can be changed at the time of program execution.  

Ques 15. What are the rules for declaring a variable in C?
Ans. Following are the specific rules which are necessary to be followed at the time of variable declaration:
1. A variable can be constructed by the digit, letter, and underscore.
2. The name of the variable begins with the letter and underscore, but not with the digit.
3. A variable cannot contain special symbols other than the underscore.
4. Users are not allowed to use the space within the variable name. 
5. A variable name must not be any keyword. 
6. _a12, v, a_12sk, etc are examples of the variable name.  

Ques 16. How to declare the variable in C?
Ans. Syntax for declaring the single variable in C programming language is:
  Data_type Variable_name;
Examples:
int var;
char _ch;
float fvar;

Syntax for declaring the multiple variables in the single statement in C programming language is:
  Data_type Variable_name1, Variable_name2, Variable_name3, ......., Variable_nameN;
Examples:
int var, a12, num2;
char character1, character2, character3;
float f1, f2, f3; 

Ques 17. What is variable initialization and how to initialize the variable in C?
Ans. Variable initialization is the process where the variable is first declared before its use in the C program. Or, we can say that it is a part where the memory location and the value is assigned to the variable. Users can also declare and initialize the variable in a single statement. 

Syntax for declaring and initializing the variable together: 
  Data_type Variable_name = value;
Examples:
int a = 10;
float fnum = 20.5;
char gender = 'M';

Syntax for declaring the multiple variable and intializing them in a single statement: 
  Data_type Variable_name1 = value, variable_name2 = value, ....., variable_nameN = value;
Examples:
int num1=10, num2 = 50, num3 = 60;
float f1 = 20.68, f2 = 100.98;
char c1 = 'a', c2 = 'x';   

Ques 18. Name the different types of variables in the C programming language?
Ans. Following are the different types of variable in the C programming language:
1. Local variable 
2. Global variable 
3. Automatic variable 
4. Static variable 
5. External variable. 

Ques 19. What is the static variable in C?
Ans. A static variable is that variable in C which is declared with the static keyword. A static variable is defined only once in the C program and preserves its value even after they exit the scope. Zero is the default value for the static variables. 
Syntax of Static variable in C:
 Static Data_type Variable_name = value;
Example:
static int number = 10; 

Ques 20. What is the external variable in C?
Ans. An external variable is that variable in C programming, which is defined outside any function body. In the C programs, we need to use the extern keyword to declare the external variable. 

Ques 21. What is the use of the static variable in C?
Ans. The uses of the static variable in C are as follows:
1. Static variables preserve their value between more than one function calls. 
2. The value of the static variable is shared as common for all the methods. 
3. These variables are defined only once to minimize memory usage. 

Ques 22. What is the scope of the variable?
Ans. Scope of the variable is that part or area of the C program where the user directly uses the variable after its declaration.

Ques 23. What is the pointer in C?
Ans. Pointers in C are used to specify the location in the memory. A pointer is a variable which stores or holds the address of another C variable.  
The pointers in C are declared using the asterisk(*) symbol. This symbol shows that the variable is a pointer which holds the address of another variable.
Syntax of Pointer:
 Data type *variable;
Example:
int *p; // This statement defines the pointer to integer (int) type. 
char *r1; // This statement defines the pointer to character (char) type. 

Ques 24. What are the keywords in C?
Ans. Keywords in C are the reserved or predefined words which have a special meaning for the compiler. In the C language, users cannot use any keyword as the constant and variable name. C programming language consists of 32 keywords and all the keywords must be written in lowercase in the C programs because C is a case-sensitive language.  

Ques 25. Enlist all the keywords of C programming language?
Ans. There are 32 keywords in the C programming language which are given in the following table: 
 auto                 break       case       char       
 const         continue    default       do
 int long register return
 short signed  sizeof  static 
 struct switch     typedef  union     
 unsigned void   volatile  while 
 double   else   enum  extern
 float  for goto if 

Ques 26. What is an auto keyword in C?
Ans. Auto keyword in C is optional. Any variable which is declared inside the block is known as an automatic or auto variable. Auto variables are also known as local variables. 

Ques 27. What is an operator in C?
Ans. An operator in C programming language is a mathematical or special symbol which tells the compiler for performing the logical operations and mathematical calculations. 
Following are the various types of operators in the C programming language:
1. Arithmetic Operators
2. Logical Operators
3. Relational Operators
4. Conditional Operator
5. Bitwise Operators
6. Assignment Operator
7. Ternary Operator
8. Special Operators

Ques 28. What is a ternary operator in C?
Ans. The ternary operator is an operator in C, which uses three operands for performing the conditional statements. It takes three operands, that's why it is called a ternary operator. This operator is also termed as the conditional operator. 
This type of operator uses two symbols '?' and ':'. 
Syntax of Ternary operator:
 Expression1 ? Expression2 : Expression3 
This operator is evaluated as: If the expression1 is true, then the expression2 executes  otherwise 
expression3 executes. 
Example of Ternary Operator:

 int main()  
 {  
    int a;  
    printf("Enter a number");  
    scanf("%d",&number);   
   (number>=100)? (printf("Hello India.....")) : (printf("Hello World....."));   // This statement contains        ternary operator
    return 0;  
 } 

Ques 29. What is the modulus operator?
Ans. Modulus operator is that operator which divides the two specified values and provides the remainder as an output of the specified two operand or values. The modulus operator is indicated by the percentage (%) sign.    
Syntax of Modulus operator:
 result = Value1  % Value2;
Example:
20 % 6
According to the modulus operator, the output of this example is 2.

Ques 30. What is a function in C?
Ans. The functions in C language are the collection of C statements which take input and perform some operations and return a meaningful output. Functions make the C program easier to use and understand. Functions reduce the code size and help the users in an easy way for debugging the code.
In C language, every program has a function which is main().  

Example of Function in C

 #include<stdio.h>  
 void multiply();  
 void main()  
 {   
    printf("\nThis program uses the function for calculating the multiplication of two numbers:");  
    multiply();  
 }  
 void multiply()  
 {  
    int x,y;   
    printf("\nEnter two numbers");  
    scanf("%d %d",&x,&y);   
    printf("The multiplication of %d and %d is %d",x,y,x*y);  
 }