Most Asked interview questions for C
C language, developed by Dennis Ritchie is the strongest programming languageĀ which is the basic stage to start with in any interview. So here are some basic interview questions which can be asked in an interview.
What is C language?
-
C is a general-purpose programming language that is extremely popular, simple, and flexible to use.
-
It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Python interpreter, and more.
Features of C
-
Procedure-based programming language
-
Simple,easy to learn and use.
-
Machine Independent or Portable
-
Fast Speed
-
Mid-level programming language
-
structured programming language
-
Rich Library
-
Memory Management
Basic data types in C
-
int: Stores an integer number
-
float: Stores a decimal number
-
double: Stores a decimal number with the highest precision
-
char: Stores a single character
-
void: Stores no value
Reserved words in C
Reserved words are something which have been predefined for a particular use, they have special meaning which can not be used for any other work.e.g. āIntā keyword is used for defining an integer variable. It can not be used for some other purpose.
There are 32 reserved words in C:
intĀ |
double |
switch |
CharĀ |
if |
short |
long |
else |
case |
enum |
auto |
typedef |
struct |
unsigned |
return |
signed |
while |
for |
Extern |
void |
union |
register |
static |
continue |
default |
DoĀ |
sizeof |
volatile |
const |
float |
GotoĀ |
BreakĀ |
What is Token?
Tokens are the smallest individual elements of a program, like variables, constants etc.
What is recursion?
Recurrence is something occurring again and again, same way recursion is a process in which the function calls itself again and again. And the function which has recursion is called a recursive function.
Why is C called a middle level programming language?
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 systems.
Why is C called the mother of all languages?
Before C language, all the languages were being used for some specific reason,they had their own way of working. When C came, it was the first language which could create anything.Ā Also,today so many languages are derived from the C language.
What is malloc() and calloc()?
malloc () and calloc() both are library functions used for allocation memory on runtime(dynamically).
malloc(): mallocĀ function allocates the memory block of given size and returns the pointer to the beginning of the block. But it doesnāt initialize the allocated memory for you. That means when the memory is allocated, it will be containing garbage value in it.So if you try to read the block just after allocation, you will get some garbage value.
calloc():callocĀ function also allocates memory of given size but it initializes the value with 0 so you will not get garbage value even if you have not stored any value in it.
What is a pointer?
Pointer is a variable that stores the address of a variable containing some value.So, basically a pointer is a variable which stores the address of another variable. Or we can say pointer points to a data type Pointers are also declared with data types depending upon which type of variableās address it needs to store.
Why do we need to declare a type of pointer when we are only storing addresses there?
Pointers always store the address of first byte of any value. Integer takes 4byte and character takes 1 bytes. So when we need to dereference we should know how many bytes we need to free depending upon the datatype.
What is Dangling Pointer?
Pointer is something which points to a memory location which stores a variable. If that variable is deleted without modifying the value of the pointer, then it is called a dangling pointer because now it is pointing to a memory address from where the object is deleted already.
What is dynamic memory allocation?
When the memory is allocated on the runtime when the program is running, that process is called dynamic memory allocation.Ā malloc(), calloc(), realloc() and free() are the functions used for dynamic memory allocation and deallocation.
What is NULL Pointer?
Null pointer is a pointer pointing to nothing or a pointer having no address.
What is the Local variable, Global variable and static variable?
Variables defined inside any function are called local variables, whereas variables defined outside a function are called global variables. Local variables are accessible only in the function but global variables can be accessed from any function of the program.
And static variables contain static values that means that value can not be changed throughout the program. Static variables are declared using the static keyword.
Which will execute first x+1 or x++??
X++ executes faster because x++ is a unary operator and has only one variable whereas in x=x+1 or x+=1 is binary operation which adds overhead; howeverĀ nowadays in some modern compilers x=x+1 is converted into x++ before compilation to make it efficient.
What is typecasting?
Type casting is the process of converting one datatype to another datatype.
What is Array?
Array is a collection of homogeneous(similar type of) data items. It is a non primitive data type which can store primitive data types like int, char, double etc.
What are pre processors?
Preprocessors are programs that process the source file and send expanded form of code to the compiler. Preprocessor programs provide preprocessor directives that tell the compiler to preprocess the source code before compiling. All of these preprocessor directives begin with a ā#ā (hash) symbol. This includes header files, macro expansions, conditional compilation, and line control.
What are control statements in C?
Control statements in C are used to control flow of the program. Normally the flow of the program is linear but if we want to control the flow e.g. if we want to execute the 10th row of the program after the 6th row based on some conditions then we will use conditional statements.