C language Interview questions
C language Interview questions
C language Interview questions
2. What is a pointer in C?
Answer: A pointer is a variable that stores the memory address of another variable.
It allows direct memory access and manipulation.
int (integer)
float (floating point)
double (double-precision floating point)
char (character)
void (no data)
6. What is sizeof() operator?
Answer: sizeof() is a compile-time operator that returns the size of a data type or
variable in bytes.
8. What is a structure in C?
Answer: A structure is a user-defined data type in C that allows grouping variables
of different data types together.
9. What is union in C?
Answer: A union is similar to a structure, but in a union, all members share the
same memory location, meaning only one member can hold a value at any given time.
20. What is the difference between int main() and void main()?
Answer:
int main() is the standard declaration, where the program returns an integer value
(typically 0 for successful execution).
25. What is the difference between stack memory and heap memory?
Answer:
Stack memory is used for static memory allocation (local variables) and is limited
in size.
Heap memory is used for dynamic memory allocation (e.g., via malloc()) and is much
larger.
28. Explain the difference between implicit and explicit type casting.
Answer:
Implicit casting is automatically done by the compiler when assigning a value to a
variable of a different type.
Explicit casting requires the programmer to manually cast a value, e.g., (int) 3.5.
auto is the default storage class for local variables, stored in the stack.
register requests that the variable be stored in a CPU register for faster access.
43. What is a volatile variable?
Answer: A volatile variable tells the compiler that the value of the variable can
change at any time, and thus it must not optimize it.
exit() performs cleanup tasks like flushing buffers before terminating the program.
_Exit() terminates the program immediately without cleanup.
An lvalue (left value) refers to an object that persists beyond a single expression
(e.g., a variable).
An rvalue (right value) is a temporary value that does not persist beyond the
expression (e.g., a constant or expression result).
59. Explain the difference between a singly linked list and a doubly linked list.
Answer:
A singly linked list has nodes with one pointer to the next node.
A doubly linked list has nodes with two pointers: one to the next node and one to
the previous node.
62. Explain the difference between shallow copy and deep copy in C.
Answer:
A shallow copy copies the reference (address) to an object, meaning changes to the
original affect the copy.
A deep copy duplicates the object itself, so the copy and original are independent.
83. What is the difference between a global variable and a static global variable?
Answer:
A global variable can be accessed from any file.
A static global variable can only be accessed within the file in which it is
defined.
exit() performs cleanup tasks such as flushing buffers before terminating the
program.
_exit() terminates the program immediately without performing cleanup.
while(1) {
// infinite loop
}