Top C Interview Question

C Programming

Who Invented C Language ?
 Denish Ritchi in 1972

What are the features of C ? 
C is the widely used language. It provides a lot of features that are given below.

Simple - It Provides structured approach(to break into parts)
Machine Independent or Portable - can be executed in mani machines with little bit or no change.
Mid-level programming language - It is used to develop system applications such as kernel, driver etc. We can also access BIOS/DOS routines.
Structured programming language - we can break the program into parts using functions. So, it is easy to understand and modify.
Rich Library - provides a lot of inbuilt functions. We can also create Library files i.e., .LIB files
Fast Speed - It compiles and executes faster.
Pointers - We can directly interact with the memory by using the pointers.
Memory Management - It supports the feature of dynamic memory allocation. We can free the allocated memory at any time by calling the free() function.
Recursion - We can call a function within a function. 
Extensible - It can easily adopt new features.

Disadvantage of C 
C is considered as difficult to learn because of its conciseness. 
It doesn't have concept of OOPs
No runtime checking
C doesn’t have the concept of constructor or destructor.

Why C is called a middle level language?
C Programming language combines the features of  both Assembly Level Language and Higher Level Language, So it is referred as Middle Language. 

What is header file ?
A header file is a file which contains C function declarations and macro definitions which has .h extension.  Example: math.h, stdio.h, conio.h etc.

What is C Token?
The smallest individual elements or units in a program are called as Tokens. Tokens can be classified as follows:
Keywords
Identifiers
Constants
Strings
Special Symbols
Operators

What is a string?
A String is a sequence of characters ending with NULL.It can be treated as one dimentional array of Characters. string is terminated with a special character '\0'.

What is Function ?
A set of statements which perform a specific task.  Every C program has at least one function, which is main() 

What is Constant?
A constant is a value that cannot be altered by the program during normal execution. They are fixed values in a program. different types of constants you can use in C.

1. Integer constants
2. Floating-point constants
3. Character constants
4. Escape Sequences
5. String constants

What is Variable?
Variables are simply names used to refer to some location in memory which can hold some value. 

What are Global Variable?
A variable that is declared outside all functions.  A global variable can be used in all functions

What are local variable?
A variable that is declared inside a functions.   A local variable can only be used in the function where it is declared.

What is Keywords?
 Keywords are those words whose meaning is already defined by Compiler and Cannot be used as Variable Name

What are the basic types of Intruction?
Type Declaration Instruction – It declares the type of variables used in a C program.
Arithmetic Instruction – It performs arithmetic operations between constants and variables
Control Instruction – It controls the sequence of execution of various statements in a C program.

What is Expression?
An expression is any legal combination of symbols that represents a value. 

What is Recursion?
In C language, a function may call another function. . A function that calls itself is known as a recursive function and This process is known as Recursion. 

What is Datatype?
Data types simply refers to the type and size of data associated with variables and functions. C language supports 2 different type of data types:
Primary data types:
These are fundamental data types in C namely integer(int), floating point(float), character(char) and void.

Derived data types:
Derived data types are nothing but primary datatypes grouped together like array, stucture, union and pointer


Difference between call by Value and Call by Reference. 
The major difference between call by value and call by reference is that, In call by value a copy of actual arguments is passed to respective formal arguments. While, In call by reference the location (address) of actual arguments is passed to formal arguments, hence any change made to formal arguments will also reflect in actual arguments.
In call by value, actual arguments will remain safe, they cannot be modified accidentally. While In call by reference, alteration to actual arguments is possible within from called function; therefore the code must handle arguments carefully else you get unexpected results.


malloc() - This function reserves a block of memory of the given size at runtime and returns a pointer of type void.
calloc() - It is another memory allocation function that is used for allocating memory at runtime. calloc function is normally used for allocating memory to derived data types such as arrays and structures.
realloc() - It changes memory size that is already allocated dynamically to a variable

What are different storage class specifiers in C?
Storage Classes in C
auto - This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language, 
register - This storage class declares register variables which have the same functionality as that of the auto variables. The only difference is that the compiler tries to store these variables in the register of the microprocessor if a free register is available., 
static - Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve the value of their last use in their scope. , 
extern - Extern storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. 

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

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

What is memory leak?
Memory leak occurs when programmers create a memory in heap and forget to delete it. 

What are local static variables? What is their use?
A local static variable is a variable whose lifetime doesn’t end with a function call where it is declared. It extends for the lifetime of complete program. All calls to the function share the same copy of local static variables. static variables get the default value as 0. 

What are static functions? What is their use?
In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static.

Difference between pointer and array in C?
An array is a collection of variables of similar data type whereas the pointer is a variable that stores the address of another variable.

Post a Comment

0 Comments