INTERVIEW QUESTIONS
1. Why do we call C a middle-level language?
Ans. C has characteristics of both assembly-level i.e. low-level and higher-level
languages. So as a result, C is commonly known as a middle-level language.
Using C, we can write an operating system as well as create an Application
Program.
2. What are the characteristics of the C language?
Ans. Some characteristics are:-
● simple and efficient.
● mid-level language.
● procedural language.
● It includes low level access to memory.
● Dynamic memory management.
● has a function rich library.
3. What are tokens in C language?
Ans. Tokens are the individual elements of a program.
6 types of tokens available in c are as follows:
● Identifiers
● Keywords
● Constants
● Operators
● Special Characters
● Strings
4. Why do we include header files in C? What if we don’t include stdio.h in
our code and use the printf scanf function , Will it work ?
Ans. In C language, header files contain the set of predefined standard library
functions. You request to use a header file in your program by including it with
the C preprocessing directive “#include”. All the header files have a ‘.h’
extension. By including a header file, we can use its contents in our program.
Even if you don’t include stdio.h in c ,And you are using printf and scanf then
also your program will compile and run without any error it will only give you
warning to include stdio.h. Even return 0 and return type is not mandatory in C.
You can try below code -
5. What is the difference between #include”…..” and #include<…..>?
Ans. The difference lies in where the preprocessor looks for the file to be
included.
For the include directive with a double quoted filename, the preprocessor
limits its search for the file to the same directory where the current source file
resides, and then to the standard directories pre-designated by the compiler.
On the other hand, when the directive uses angle brackets, the preprocessor
searches for the file in directories pre-designated by the compiler - usually
directories where standard library header files reside.
6. Why do we write return 0 at the end of our main() function?
Ans. when we return something it gives our status of the program to the caller
(here for main() function OS is the caller). return 0 at the end of our main()
function shows the program has been executed successfully.
7. What happens if we return -1 or return any other number in our code?
Ans. As the return statement provides the status of our program to the caller
when we return 0 it shows successful execution of code, while returning any
positive number shows that the program may contain some warnings or
somewhere logic is going wrong but returning -1 or any negative number shows
that there is error in our program. As C does not support exception handling,
returning -1 gives the status of errors to the OS.
8. Can we leave the main() function in C language empty?
Ans - Yes , But your program will do nothing. You just need the “return 0;”
statement, unless the main function is declared as “void main()”
9. What is the memory representation of int x = 10?
Ans - When the compiler sees the int x = 10; It understands that you need to
allocate a memory of size 4 byte to store an integer number 10. So first it
allocates 4 byte memory to you having an address and you can access that
location by name x and at the same time it initializes the location with 10 as an
integer.
10. Explain about the cyclic property of data types in C language?
Ans.
#include<stdio.h>
int main(){
signed char c1=130;
signed char c2=-130;
printf("%d %d",c1,c2);
return 0;
}
Output: -126 126 (why?)
This situation is known as overflow of signed char.
Range of unsigned char is -128 to 127. If we assign a value greater than 127
then the value of the variable will be changed to a value if we move clockwise
as shown in the figure according to the number. If we will assign a number
which is less than -128 then we have to move in anti-clockwise direction.
11. What are the data types in C? What is the difference between them?
Ans. Integer data type allows a variable to store numeric values. The storage
size of int data type is 2 or 4 or 8 byte varies depending upon the processor in
the CPU.
Character data type allows a variable to store only one character. Storage size
of the character data type is 1.
Float data type allows a variable to store decimal values. Storage size of the
float data type is 4. This also varies depending upon the processor in the CP.
Double data type is also the same as float data type which allows up-to 10 digits
after decimal.
12. What is the use of the sizeof() function?
Ans. sizeof() function in C is used to find the memory space allocated to each
data type.
13. What is the type Casting in C?
Ans. Type Casting in C helps to convert the data type of one variable to another
explicitly by the programmer.
Type Conversion can be performed in two ways:
● Implicit Type Conversion: This is performed by the compiler
automatically without any manual indication. It is performed by the
compiler during the execution of an expression where two or more data
types are present. The small data types are converted into large data types
so that data is preserved without any loss.
● Explicit Type Conversion or Type Casting: It is deliberately performed
by the programmer in the code by mentioning the required data type and
this is known as typecasting in C.
14. What is Enum in C?
Ans. Enumeration is a data type that consists of named integer constants as a
list. It starts with 0 (zero) by default and value is incremented by 1 for the
sequential identifiers in the list.
15. What is the difference between variable declaration and variable
definition in C?
Ans.
Variable Declaration Variable Definition
Variable declaration tells the compiler variable definition allocates memory
about the data type and size of the to the variable
variable.
Variables can be declared many times definition can happen only one time
in a program. for a variable in a program.
Variable declaration is for assignment variable definition is for assignments
of properties and identification to a of storage space to a variable.
variable.
16. What do you know about local variables and global variables in C?
Ans.
Local Variables: The variables which are having scope/life only within the
function are called local variables. These variables are declared within the
function and can’t be accessed outside the function.
Global Variables: The variables which are having scope/life throughout the
program are called global variables. Global variable is defined outside the main
function. So, this variable is visible to the main function and all other sub
functions.
17. What do you mean by the Scope of the variable? What is the scope of
the variables in C?
Ans. 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.
18. What do you mean by Macro? Why do we use it?
Ans. Macro is a name which is given to a value or to a piece of code/block in a
program. Instead of using the value, we can use a macro which will replace the
value in a program.
Consider below example:
You are using a value of pi in many places in your program. If you use a macro
in your program, it is very simple to replace the value of pi i.e., 3.14 by directly
writing pi and we can change in only one place which will change the value in
all places in your program.
Syntax: #define <MACRO_NAME> VALUE
Example: #define pi 3.14
19. What is the difference between auto variable and static variable in C?
Ans. Both auto and static variables are local variables.
Scope of static variables is within the function only but can retain the value of
the variable between different function calls.
Whereas auto variables cannot retain the value of the variable between different
function calls.
20. What is the difference between auto variable and register variable in C?
Ans. Storage class of all variables are auto by default unless we specify a
variable is register or static or extern in C program.
● Both auto variable and register variable are local variables. Register
variables are stored in register memory. Whereas, auto variables are
stored in main CPU memory.
● Register variables will be accessed very faster than the normal/auto
variables since they are stored in register memory rather than main
memory.
● But, only limited variables can be used as registers since register size is
very low. (16 bits, 32 bits or 64 bits)
Follow us:
Website - https://ineuron.ai/
Linkedin -
https://www.linkedin.com/company/ineuron-ai/mycompany/
https://www.linkedin.com/in/saurabh-shukla-5b73bb6/
https://www.linkedin.com/in/prateek-jain-iitr/
Youtube Channel -
https://www.youtube.com/c/iNeuroniNtelligence
https://www.youtube.com/user/saurabhexponent1
https://www.youtube.com/c/PrateekJainAcademy