Interview questions for C programme
1. What is C language?
C is a mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation.More details.
2. What are different storage class specifiers in C?
Auto, register, static, extern
3. What do you mean by Dangling Pointer Variable in C Programming?
A Pointer in C Programming is used to point the memory location of an existing variable. In case if that particular variable is deleted and the Pointer is still pointing to the same memory location, then that particular pointer variable is called as a Dangling Pointer Variable.
4. What is scope of a variable? How are variables scoped in C?
Scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped. See this for more details.
5. Why is C known as a mother language?
6. What do you mean by the Scope of the variable? What is the scope of the variables in C?
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.
7. When should we use pointers in a C program?
• To get address of a variable.
• For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables.
• To pass large structures so that complete copy of the structure can be avoided.
• To implement “linked” data structures like linked lists and binary trees.
8. Why is C called a mid-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 system.
9. Differentiate between Actual Parameters and Formal Parameters?
The Parameters which are sent from main function to the subdivided function are called as Actual Parameters and the parameters which are declared a the Subdivided function end are called as Formal Parameters.
10. 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. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program.
11. What is the use of the function in C?
Uses of C function are:
o C functions are used to avoid the rewriting the same code again and again in our program.
o C functions can be called any number of times from any place of our program.
o When a program is divided into functions, then any part of our program can easily be tracked.
o C functions provide the reusability concept, i.e., it breaks the big task into smaller tasks so that it makes the C program more understandable.
12. How can we store a negative integer?
To store a negative integer, we need to follow the following steps. Calculate the two’s complement of the same positive integer.
Ex: 1011 (-5)
Step-1 − One’s complement of 5: 1010
Step-2 − Add 1 to above, giving 1011, which is -5
13. 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, so that the pointer still points to the memory location of the deallocated memory. Following are examples.
// EXAMPLE 1
int* ptr = (int*)malloc(sizeof(int));
// ptr is a dangling pointer now and operations like following are invalid
*ptr = 10; // or printf(“%d”, *ptr);
14. What is memory leak? Why it should be avoided?
Memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.
/* Function with memory leak */
int* ptr = (int*)malloc(sizeof(int));
/* Do some work */
return; /* Return without freeing ptr*/
15. What are static variables and functions?
The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.
16. Differentiate between calloc() and malloc()?
calloc() and malloc() are memory dynamic memory allocation functions. The only difference between them is that calloc() will load all the assigned memory locations with value 0 but malloc() will not.
17. What is a NULL pointer in C?
A pointer that doesn’t refer to any address of value but NULL is known as a NULL pointer. When we assign a ‘0’ value to a pointer of any type, then it becomes a Null pointer.
18. What are the valid places where the programmer can apply Break Control Statement?
Break Control statement is valid to be used inside a loop and Switch control statements.
19. What is the structure?
• The structure is a user-defined data type that allows storing multiple types of data in a single unit. It occupies the sum of the memory of all members.
• The structure members can be accessed only through structure variables.
• Structure variables accessing the same structure but the memory allocated for each variable will be different.
20. What is typecasting?
Typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.
1 (type_name) expression;