C Theory Interview Questions

19 Jul 2025 Anvesh G 0 C Programming



🔧 1. Compilation & Program Execution

  1. How does a C program compile and run?

  2. What are different stages in C compilation?

  3. What is the difference between compiler and interpreter?

  4. What is the output of the preprocessor?

  5. What is the difference between #include <file.h> and #include "file.h"?

  6. What are gcc, as, ld, and objdump?

  7. What is the role of a linker?

  8. What are object files?

  9. What is a segmentation fault?

  10. What is the difference between exit() and _exit()?

  11. What is the use of volatile?

  12. What is const volatile int* p?

  13. What is the startup routine in C (_start, main)?

  14. What happens when main() returns?

  15. Can we execute code without main()?

  16. Difference between int main() and void main()?


📦 2. Storage Classes & Memory Layout

  1. What are different storage classes in C?

  2. What is the use of static keyword in global and local scope?

  3. What is the use of extern keyword?

  4. What is the use of register?

  5. What is the memory layout of a C program?

  6. What are .text, .data, .bss, heap and stack?

  7. Where are static/global variables stored?

  8. Why can't a global variable be declared as register?

  9. Can two static variables have the same address?

  10. Output of static int x = x + 1;


🧠 3. Functions & Function Pointers

  1. What is a function pointer?

  2. How to declare and use an array of function pointers?

  3. Can we return a function pointer?

  4. How to call a function using a pointer?

  5. What is callback in C?

  6. How is recursion handled internally?

  7. Can a function be declared inside another function?

  8. What is the signature of main() with arguments?

  9. How are arguments passed (stack/register)?

  10. Use function pointers for dispatcher implementation


🧮 4. Arrays & Strings

  1. Difference between char[] and char*?

  2. Can arrays be returned from a function?

  3. How to reverse a string without library functions?

  4. How to reverse a word in a string?

  5. Implement strlen() and strcpy() manually.

  6. What happens if we modify string literals?

  7. Difference between char arr[] = "abc"; and char *p = "abc";

  8. Why are strings terminated with \0?

  9. How to implement your own atoi()?


🧱 5. Memory Allocation

  1. What is malloc, calloc, realloc, free?

  2. What is the default alignment of malloc()?

  3. What is the difference between stack and heap memory?

  4. What happens if we free() an already freed pointer?

  5. What is a memory leak?

  6. What is valgrind?

  7. Can you implement your own memory allocator?

  8. Use of mmap() for memory allocation.

  9. What is a slab or pool allocator?

  10. What is use-after-free error?


🔗 6. Pointers

  1. What is a wild pointer?

  2. What is a dangling pointer?

  3. What is pointer arithmetic?

  4. What is the difference between *p++ and (*p)++?

  5. Can function return a pointer to a static variable?

  6. Difference between pointer to pointer and array of pointers?

  7. Implement 2D array using pointer-to-pointer.

  8. What is the output of:

int *p; *p = 10;

⚙️ 7. Macros & Preprocessor

  1. What are macros and how are they expanded?

  2. What is the difference between #define and const?

  3. What is a multi-line macro?

  4. What is token pasting (##)?

  5. What is stringification (#)?

  6. What is the use of #pragma?

  7. Can macros be redefined?

  8. Write a macro to return maximum of two values.


🏗️ 8. Structures, Unions & Enums

  1. What is structure padding?

  2. How to remove padding in structures?

  3. What is structure packing?

  4. What is the difference between structure and union?

  5. What is a flexible array member?

  6. Can a structure have pointer to itself?

  7. How to serialize/deserialize a structure?

  8. What is an anonymous structure or union?

  9. Difference between -> and . operators?


🔄 9. Type Qualifiers & Casting

  1. What is const int*, int const*, int* const?

  2. What is implicit vs explicit typecasting?

  3. How to typecast void pointer?

  4. Can we cast one structure to another?

  5. Write a typedef for function pointer.


🧵 10. Multithreading & Concurrency (Embedded Focused)

  1. What is a race condition?

  2. How to avoid race conditions?

  3. Difference between mutex and binary semaphore?

  4. How to create a thread in Linux using pthread_create()?

  5. How to share data between threads safely?

  6. What are mutex, semaphore, and spinlock?

  7. Is malloc() thread-safe?

  8. Can we interrupt a thread?

  9. How to cancel a thread?


🐞 11. Debugging & Tools

  1. What is gdb?

  2. How to debug segmentation fault in C?

  3. What are nm, readelf, and objdump?

  4. What is use of strace and ltrace?

  5. How does valgrind help?

  6. What are -Wall, -g, -O0, -O2, -static flags?

  7. What is difference between make and gcc?

  8. How does make resolve dependencies?

  9. What are core dumps and how to analyze them?


💡 12. Miscellaneous & Tricky

  1. Can main() be called recursively?

  2. Can we write main() as int main(void)?

  3. Can we assign a value to const int using a pointer?

  4. What is undefined behavior? Give 3 examples.

  5. What is sequence point?

  6. What is endianess?

  7. How to check little/big endian in C?

  8. What is use of offsetof() macro?

  9. What is interrupt handling? Can it be written in C?

  10. What happens if we overflow the stack?

  11. Can we modify return address in stack?

  12. What is a segmentation fault vs bus error?

  13. What is a trap instruction?

  14. How does the kernel call user main()?

  15. Can printf() be thread-safe?

  16. Difference between dynamic and static libraries?

  17. Can we allocate memory in .text segment?


🔁 13. Recently Added Extensions

  1. Can structure have a static member?

  2. Can we modify a constant global using pointer?

  3. Difference between shallow and deep copy?

  4. Difference between union and bit-fields?

  5. Implement singly linked list reversal in C.

  6. What is the output of ++*p++?

  7. How to use offsetof() with alignment?

  8. What happens when you free a pointer twice?

  9. What is memory alignment and padding?

  10. Can we declare a variable with same name as function?



Author
BY: Anvesh G

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.