What is the difference between an array and a pointer in C?
An array is a collection of elements of the same data type stored in contiguous memory locations, while a pointer is a variable that stores the memory address of another variable.
What is a pointer in C?
A pointer is a variable that holds the memory address of another variable. It allows direct manipulation of memory and enables dynamic memory allocation.
What is the purpose of the “const” keyword in C?
The const keyword is used to declare constants in C. It specifies that a variable’s value cannot be changed once it is assigned.
What is the difference between “malloc()” and “calloc()”?
malloc() is used to allocate a block of memory of the specified size, while calloc() is used to allocate and initialize memory, setting all bytes to zero.
What is a structure in C?
A structure in C is a user-defined data type that allows the grouping of different variables of different types under a single name. It is used to represent a record or a collection of related data.
What is the purpose of the “typedef” keyword in C?
The typedef keyword is used to create a new name for an existing data type. It provides a way to define custom names for complex data types, improving code readability and maintainability.
What is the “volatile” keyword used for in C?
The volatile keyword informs the compiler that a variable can be modified by external sources, so it should not optimize or cache its value. It is commonly used for variables accessed by multiple threads or interrupt service routines.
Explain the difference between “static” and “extern” keywords in C.
The static keyword is used to declare variables and functions with internal linkage. It restricts their scope to the file in which they are defined.
The extern keyword is used to declare variables and functions that are defined in other files. It extends their scope beyond the current file.
What is the purpose of the “sizeof” operator in C?
The sizeof operator is used to determine the size in bytes of a variable, data type, or expression. It is often used for memory allocation and array indexing.
Explain the concept of recursion in C.
Recursion is a programming technique in which a function calls itself to solve a problem. It involves breaking down a problem into smaller subproblems until a base case is reached.
What is the difference between “const char *ptr” and “char *const ptr”?
“const char *ptr” means that the data pointed to by “ptr” is constant and cannot be modified, but “ptr” itself can be reassigned to point to other data.
“char *const ptr” means that “ptr” is a constant pointer that cannot be reassigned to point to other data, but the data it points to can be modified.
Explain the use of the “break” statement in C.
The “break” statement is used to exit from a loop or switch statement. It terminates the innermost loop or the switch statement and transfers control to the next statement after the loop or switch.
What is the difference between “malloc()” and “realloc()”?
malloc() is used to allocate a block of memory of the specified size, while realloc() is used to resize an already allocated block of memory, either increasing or decreasing its size.