1. What is C language?
C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. 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.
- Simple: C is a simple language because it follows the structured approach, i.e., a program is broken into parts.
- Portable: C is highly portable means that once the program is written can be run on any machine with little or no modifications.
- Mid Level: C is a mid-level programming language as it combines the low- level language with the features of the high-level language.
- Structured: C is a structured language as the C program is broken into parts.
- Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
- Extensible: C is an extensible language as it can adopt new features in the future.
- Memory Management: C provides an inbuilt memory function that saves the memory and improves the efficiency of our program.
4. What is the use of a static variable in C?
- A variable which is declared as static is known as a static variable. The static variable retains its value between multiple function calls.
- Static variables are used because the scope of the static variable is available in the entire program. So, we can access a static variable anywhere in the program.
- The static variable is initially initialized to zero. If we update the value of a variable, then the updated value is assigned.
- The static variable is used as a common value which is shared by all the methods.
- The static variable is initialized only once in the memory heap to reduce the memory usage.
5. What is the use of the function in C?
Uses of C function are:
- C functions are used to avoid the rewriting the same code again and again in our program.
- C functions can be called any number of times from any place of our program.
- When a program is divided into functions, then any part of our program can easily be tracked.
- 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.
6. 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.
Syntax:
data_type array_name[size];
Multidimensional array: Multidimensional array is an array that contains more than one array.
Syntax:
data_type array_name[size];
7. 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:
1. Winding phase
2. 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.
13. What is pointer to pointer in C?
14. 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.
16. What functions are used for dynamic memory allocation in C language?
17. What is the difference between malloc() and calloc()?
calloc() |
malloc() |
|
Description |
The malloc() function allocates a single block of requested
memory. |
The calloc() function allocates multiple blocks of requested memory. |
Initialization |
It initializes the content of the memory to zero. |
It does not initialize the content of memory, so it carries
the garbage value. |
Number of arguments |
It consists of two arguments. |
It consists of only one argument. |
Return value |
It returns a pointer pointing to the allocated memory. |
It returns a pointer pointing to the allocated memory. |
18. What is the difference between call by value and call by
reference in C?
Call by value |
Call by reference |
|
Description |
When a copy of the value is passed to the function, then the original value is not modified. |
When a copy of the value is passed to the function, then the original value is modified. |
Memory location |
Actual arguments and formal arguments are created in separate
memory locations. |
Actual arguments and formal arguments are created in the same memory location. |
Safety |
In this case, actual arguments remain safe as they cannot be
modified. |
In this case, actual arguments are not reliable, as they are
modified. |
Arguments |
The copies of the actual arguments are passed to the formal
arguments. |
The addresses of actual arguments are passed to their respective formal arguments. |
19. What is the difference between the local variable and global variable in C?
Basis for comparison |
Local variable |
Global variable |
Declaration |
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. |
Scope |
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. |
Access |
Variables can be accessed only by those statements inside a function in which they are
declared. |
Any statement in the entire program can access variables. |
Life |
Life of a variable is created when the function block is entered and destroyed on its
exit. |
Life of a variable exists until the program is executing. |
Storage |
Variables are stored in a stack unless specified. |
The compiler decides the storage location of a variable. |
20. 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.
21. What is a union?
The union is a user-defined data type that allows storing multiple types of data in a single unit. However, it doesn't occupy the sum of the memory of all members. It holds the memory of the largest member only.
In union, we can access only one variable at a time as it allocates one common space for all the members of a union.
Syntax of union
union union_name
{
Member_variable1;
Member_variable2;
Member_variable n;
}[union variables];
22. What is an auto keyword in C?
23. What is the purpose of sprintf() function?
The sprintf() stands for "string print." The sprintf() function does not print the output on the console screen. It transfers the data to the buffer. It returns the total number of characters present in the string.
Syntax
int sprintf ( char * str, const char * format, ... );
24. Can we compile a program without main() function?
Yes, we can compile, but it can't be executed.
But, if we use #define, we can compile and run a C program without using the main() function. For example:
#include<stdio.h>
#define start main
void start() {
printf("Hello");
}
25. What is a token?
The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest individual unit in a program. C has the following tokens:
Identifiers: Identifiers refer to the name of the variables.
Keywords: Keywords are the predefined words that are explained by the compiler.
Constants: Constants are the fixed values that cannot be changed during the execution of a program.
Operators: An operator is a symbol that performs the particular operation.
Special characters: All the characters except alphabets and digits are treated as special characters.
27. What is the difference between getch() and getche()?
28. What is typecasting?
The 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.
Syntax
(type_name) expression;
29. What is a built-in function in C?
30. How can a string be converted to a number?
31. Why doesn’t C support function overloading?
32. Difference between const char* p and char const* p?
- const char* p is a pointer to a const char.
- char const* p is a pointer to a char const.