Ultimate C Programming Interview Questions and Answers (With Coding Examples)
💻 Ultimate C Programming Interview Questions and Answers
If you're preparing for an IT job interview that includes C programming, this guide has everything you need. From beginner to advanced, here are the most asked C interview questions with answers and code examples.
🟢 1. Basic C Concepts
Q1. What is C language?
A procedural programming language developed in 1972. Still used for OS, embedded systems, and compilers due to its performance and control.
Q2. Difference between printf() and scanf()
Feature | printf() | scanf() |
---|---|---|
Function | Output | Input |
Address Operator | Not needed | Required (&) |
Q3. What is a pointer?
int x = 10;
int *ptr = &x;
printf("%d", *ptr); // Output: 10
Q4. Difference between ++i and i++
int i = 5;
printf("%d", ++i); // 6
printf("%d", i++); // 6 (but i becomes 7)
Q5. malloc() vs calloc()
Function | malloc() | calloc() |
---|---|---|
Memory | Uninitialized | Initialized to 0 |
Syntax | malloc(size) | calloc(n, size) |
🟡 2. Intermediate Questions
Q6. What is a static variable?
void counter() {
static int count = 0;
count++;
printf("%d ", count);
}
Q7. What is const?
const int x = 10;
x = 20; // Error
Q8. Structure vs Array
Feature | Structure | Array |
---|---|---|
Data Types | Different | Same |
Access | Dot operator | Index |
Q9. What is recursion?
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
Q10. Pass by value vs reference
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
🔴 3. Advanced C Questions
Q11. What is a memory leak?
Occurs when dynamically allocated memory is not freed using free()
.
Q12. What is a function pointer?
int add(int a, int b) { return a + b; }
int (*fp)(int, int) = add;
printf("%d", fp(3, 4));
Q13. What is volatile?
Tells the compiler not to optimize the variable. Used in hardware programming.
Q14. What is typedef?
typedef unsigned int uint;
uint age = 25;
Q15. Use of sizeof()
printf("%lu", sizeof(int));
💻 4. Coding Questions
Q16. Check Prime
int isPrime(int n) {
if (n <= 1) return 0;
for (int i = 2; i*i <= n; i++) {
if (n % i == 0) return 0;
}
return 1;
}
Q17. Reverse String
void reverse(char *str) {
int l = strlen(str);
for (int i = 0; i < l/2; i++) {
char t = str[i];
str[i] = str[l-i-1];
str[l-i-1] = t;
}
}
Q18. Largest in Array
int findMax(int arr[], int n) {
int max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > max) max = arr[i];
}
return max;
}
Q19. Swap without temp
void swap(int *a, int *b) {
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
Q20. Check Palindrome
int isPalindrome(char *str) {
int l = strlen(str);
for (int i = 0; i < l/2; i++) {
if (str[i] != str[l-i-1]) return 0;
}
return 1;
}
✅ 5. Interview Tips
- Revise syntax, pointers, memory management.
- Practice without IDE (use whiteboard).
- Explain logic during interviews clearly.
- Use online judges like HackerRank, LeetCode.
- Prepare with mock interviews or peers.
Bonus: Want to target FAANG? Practice DSA in C and master Linux system calls, GCC, and file I/O!
🚀 All the best! Comment below if you want more practice sets or a downloadable PDF version!
Comments
Post a Comment