C Programming Interview Questions
C is a mid level and procedural programming language.
2) Why C is known as a mother language?
C is known as a mother language because most of the compilers, kernals and JVMs are written in C language.
3) Why C is called a mid level programming language?
It supports the feature of both low-level and high level languages that is why it is known as a mid level programming language.
4) Who is the founder of C language?
Dennis Ritchie.
5) When C language was developed?
C language was developed in 1972 at bell laboratories of AT&T.
6) What are the features of C language?
The main features of C language are given below:
Simple
Portable
Mid Level
Structured
Fast Speed
Memory Management
Extensible
7) What is the use of printf() and scanf() functions?
The printf() function is used for output and scanf() function is used for input.
8) What is the difference between local variable and global variable in C?
Local variable: A variable which is declared inside function or block is known as local variable.
Global variable: A variable which is declared outside function or block is known as global variable.
int value=50;//global variable
void function1(){
int x=20;//local variable
}
9) What is the use of static variable in C?
A variable which is declared as static is known as static variable. The static variable retains its value between multiple function calls.
void function1(){
int x=10;//local variable
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d\n",x);//will always print 11
printf("%d\n",y);//will always increment value, it will print 11, 12, 13 and so on
}
10) What is the use of function in C?
A function in C language provides modularity. It can be called many times. It saves code and we can reuse the same code many times.
We can pass value to function by one of the two ways: call by value or call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified. But in case of call by reference, an address of value of passed to the function, so original value is modified.
Calling the same function, inside function is known as recursion. For example:
function1();//calling same function
}
13) What is array in C?.
Array is a group of similar types of elements. It has contiguous memory location. It makes the code optimized, easy to traverse and easy to sort.
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast.
Accessing array elements
Dynamic memory allocation
Call by Reference
Data Structures like tree, graph, linked list etc.
A pointer that doesn't refer to any address of a value but NULL, is known as NULL pointer. For example:
17) What is far pointer in C?
A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer.
If a pointer is pointing any memory location but meanwhile another pointer deletes the memory occupied by first pointer while first pointer still points to that memory location, first pointer will be known as dangling pointer. This problem is known as dangling pointer problem.
In case of static memory allocation, memory is allocated at compile time and memory can't be increased while executing the program. It is used in array.
In case of dynamic memory allocation, memory is allocated at run time and memory can be increased while executing the program. It is used in linked list.
malloc()
calloc()
realloc()
free()
23) What is the difference between malloc() and calloc()?
malloc(): The malloc() function allocates single block of requested memory. It has garbage value initially.
calloc(): The calloc() function allocates multiple block of requested memory. It initially initializes all bytes to zero.
24) What is structure?
Structure is a user-defined data type that allows to store multiple types of data in a single unit. It occupies the sum of memory of all members.
Like Structure, union is a user-defined data type that allows to store multiple types of data in a single unit. But it doesn't occupies the sum of memory of all members. It occupies the memory of largest member only.
In C, every local variable of a function is known as automatic (auto) variable. Let's explain with an example:
{
int i ;
auto int j;
} Here, both 'i' and 'j' variables are automatic variables.
Note: A global variable can't be an automatic variable.
It is used to print the formatted output into char array.
Yes, we can compile but it can't be executed.
But, if we use #define, we can compile and run C program without using main() function. For example:
#define start main
void start() {
printf("Hello");
}
29) What is token?
Token is an identifier. It can be constant, keyword, string literal etc.
The argument passed to the main() function while executing the program is known as command line argument.
//code to be executed
}
31) What is the acronym for ANSI?
American National Standard Institute.
The getch() function reads a single character from keyboard. It doesn't uses any buffer, so entered data is not displayed on the output screen.
The getche() function reads a single character from keyword but data is displayed on the output screen. Press Alt+f5 to see the entered character.
The new line escape sequence is represented by "\n". It inserts a new line on the output screen.
Brain Kernighan.
A virtual address is composed of selector and offset.
A near pointer doesn't have explicit selector whereas far and huge pointers have explicit selector. When you perform pointer arithmetic on far pointer, selector is not modified but in case of huge pointer it can be modified.
These are the non-standard keywords and implementation specific. These are irrelevant in modern platform.
Converting one data type into another is known as typecasting. For example:
int a=(int)f;//typecasting
The fopen() function is used to open file whereas fclose() is used to close file.
Yes, by holding the base address of array into pointer, we can access the array using pointer.
A loop running continuously for indefinite number of times is called infinite loop.I
nfinite For Loop:
//code to be executed
}
No comments:
Post a Comment