C Programming Interview Questions
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
C is known as a mother language because most of the compilers and JVMs are written in C language.
Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages.
Simple: C is a simple language because it follows the structured approach, i.e., a program is broken into parts
Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
Memory Management: C provides an inbuilt memory function that saves the memory and improves the efficiency of our program.
Structured: C is a structured language as the C program is broken into parts.
Local variable | Global variable |
---|---|
A variable which is declared inside function or block is known as a local variable. | A variable which is declared outside function or block is known as a global variable. |
The scope of a variable is available within a function in which they are declared. | The scope of a variable is available throughout the program. |
Variables are stored in a stack unless specified. | The compiler decides the storage location of a variable. |
1.C functions are used to avoid the rewriting the same code again and again in our program.
2.C functions can be called any number of times from any place of our program.
3.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.
When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function.
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.
Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters which is terminated by a null character '\0'.
Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like tree, graph, linked list, etc.
Call by Reference: The pointers are used to pass a reference of a variable to other function.
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. In static memory, more memory space is required to store the variable.
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.
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.
No comments:
Post a Comment