1. What is C language and why is it still used?
Answer:
C is a general-purpose, procedural programming language developed in 1972 by Dennis Ritchie.
It is still widely used because of its efficiency, portability, and close interaction with hardware. Many modern languages like C++, Java, and Python are based on C concepts.
2. What are the key features of C?
Simple and fast
Portable across platforms
Structured programming (functions)
Low-level access (pointers, memory management)
Large standard library
3. Difference between ++i
and i++
++i
→ Pre-increment → Increasesi
first, then returns value.i++
→ Post-increment → Returns current value, then increasesi
.
#include
int main() {
int i = 5;
printf("%d\n", ++i); // Output: 6
printf("%d\n", i++); // Output: 6 (then i becomes 7)
return 0;
}
4. What is a pointer in C?
Answer:
A pointer is a variable that stores the memory address of another variable.
They are widely used for dynamic memory allocation, arrays, and function arguments.
Example:
#include
int main() {
int num = 10;
int *ptr = #
printf("Value: %d\n", *ptr); // 10
printf("Address: %p\n", ptr); // Memory address of num
return 0;
}
5. What is the difference between malloc()
and calloc()
?
malloc() → Allocates a single block of memory (uninitialized).
calloc() → Allocates multiple blocks and initializes them to zero.
int *a = (int*)malloc(5 * sizeof(int)); // Garbage values
int *b = (int*)calloc(5, sizeof(int)); // All values set to 0
6. What are storage classes in C?
They define the scope, lifetime, and visibility of variables.
auto
→ Default, local variableregister
→ Stored in CPU register (fast access)static
→ Preserves value across function callsextern
→ Declared globally, used across files
7. Common C Programming Tricky Question
Q: What will this code output?
#include
int main() {
int a = 10;
printf("%d %d %d", a, a++, ++a);
return 0;
}
Answer:
The output is undefined behavior because the order of evaluation of function arguments is not specified in C.
8. Tips to Prepare for C Interviews
Revise C fundamentals: variables, loops, functions, arrays, pointers.
Practice DSA concepts in C (linked list, stack, queue, trees).
Solve common coding problems (palindrome, prime number, sorting).
Understand memory management (malloc, free, pointers).
Be clear about time complexity of common algorithms.