11) What is recursion in C?
When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function.
Recursive function comes in two phases:
- Winding phase
- Unwinding phase
Winding phase: When the recursive function calls itself, and this phase ends when the condition is reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the control returns to the original call.
12) What is an array in C?
An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration.
Arrays are of two types:
- One-dimensional array: One-dimensional array is an array that stores the elements one after the another.
- Multidimensional array: Multidimensional array is an array that contains more than one array.
13) What is a pointer in C?
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast. Whenever a variable is declared inside a program, then the system allocates some memory to a variable. The memory contains some address number. The variables that hold this address number is known as the pointer variable.
14) What is the usage of the pointer in C?
- Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters that is terminated by a null character ‘\0’.
- Dynamic memory allocation: Pointers are used in the allocation and deallocation of memory during the execution of a program.
- Call by Reference: The pointers are used to pass a reference of a variable to another function.
- Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like trees, graphs, linked lists, etc.
15) 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.
16) What is a far pointer in C?
A pointer that can access all the 16 segments (whole residence memory) of RAM is known as far pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given section.
17) What is dangling pointer in C?
- If a pointer is pointing to any memory location, but meanwhile another pointer deletes the memory occupied by the first pointer while the first pointer still points to that memory location, the first pointer will be known as a dangling pointer. This problem is known as a dangling pointer problem.
- A dangling pointer arises when an object is deleted without modifying the value of the pointer. The pointer points to the deallocated memory.
18) What is pointer to pointer in C?
In case of a pointer to pointer concept, one pointer refers to the address of another pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains the address of a variable. The pointer to pointer contains the address of a first pointer.
19) What is static memory allocation?
- 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 the array.
- The lifetime of a variable in static memory is the lifetime of a program.
- The static memory is allocated using static keyword.
- The static memory is implemented using stacks or heap.
- The pointer is required to access the variable present in the static memory.
- The static memory is faster than dynamic memory.
- In static memory, more memory space is required to store the variable.
20) What is dynamic memory allocation?
- In case of dynamic memory allocation, memory is allocated at runtime and memory can be increased while executing the program. It is used in the linked list.
- The malloc() or calloc() function is required to allocate the memory at the runtime.
- An allocation or deallocation of memory is done at the execution time of a program.
- No dynamic pointers are required to access the memory.
- The dynamic memory is implemented using data segments.
- Less memory space is required to store the variable.