C Theory Interview Questions
🔧 1. Compilation & Program Execution
-
How does a C program compile and run?
-
What are different stages in C compilation?
-
What is the difference between compiler and interpreter?
-
What is the output of the preprocessor?
-
What is the difference between
#include <file.h>
and#include "file.h"
? -
What are
gcc
,as
,ld
, andobjdump
? -
What is the role of a linker?
-
What are object files?
-
What is a segmentation fault?
-
What is the difference between
exit()
and_exit()
? -
What is the use of
volatile
? -
What is
const volatile int* p
? -
What is the startup routine in C (
_start
,main
)? -
What happens when
main()
returns? -
Can we execute code without
main()
? -
Difference between
int main()
andvoid main()
?
📦 2. Storage Classes & Memory Layout
-
What are different storage classes in C?
-
What is the use of
static
keyword in global and local scope? -
What is the use of
extern
keyword? -
What is the use of
register
? -
What is the memory layout of a C program?
-
What are
.text
,.data
,.bss
, heap and stack? -
Where are static/global variables stored?
-
Why can't a global variable be declared as
register
? -
Can two static variables have the same address?
-
Output of
static int x = x + 1;
🧠 3. Functions & Function Pointers
-
What is a function pointer?
-
How to declare and use an array of function pointers?
-
Can we return a function pointer?
-
How to call a function using a pointer?
-
What is callback in C?
-
How is recursion handled internally?
-
Can a function be declared inside another function?
-
What is the signature of
main()
with arguments? -
How are arguments passed (stack/register)?
-
Use function pointers for dispatcher implementation
🧮 4. Arrays & Strings
-
Difference between
char[]
andchar*
? -
Can arrays be returned from a function?
-
How to reverse a string without library functions?
-
How to reverse a word in a string?
-
Implement
strlen()
andstrcpy()
manually. -
What happens if we modify string literals?
-
Difference between
char arr[] = "abc";
andchar *p = "abc";
-
Why are strings terminated with
\0
? -
How to implement your own
atoi()
?
🧱 5. Memory Allocation
-
What is
malloc
,calloc
,realloc
,free
? -
What is the default alignment of
malloc()
? -
What is the difference between stack and heap memory?
-
What happens if we
free()
an already freed pointer? -
What is a memory leak?
-
What is
valgrind
? -
Can you implement your own memory allocator?
-
Use of
mmap()
for memory allocation. -
What is a slab or pool allocator?
-
What is use-after-free error?
🔗 6. Pointers
-
What is a wild pointer?
-
What is a dangling pointer?
-
What is pointer arithmetic?
-
What is the difference between
*p++
and(*p)++
? -
Can function return a pointer to a static variable?
-
Difference between pointer to pointer and array of pointers?
-
Implement 2D array using pointer-to-pointer.
-
What is the output of:
int *p; *p = 10;
⚙️ 7. Macros & Preprocessor
-
What are macros and how are they expanded?
-
What is the difference between
#define
andconst
? -
What is a multi-line macro?
-
What is token pasting (
##
)? -
What is stringification (
#
)? -
What is the use of
#pragma
? -
Can macros be redefined?
-
Write a macro to return maximum of two values.
🏗️ 8. Structures, Unions & Enums
-
What is structure padding?
-
How to remove padding in structures?
-
What is structure packing?
-
What is the difference between structure and union?
-
What is a flexible array member?
-
Can a structure have pointer to itself?
-
How to serialize/deserialize a structure?
-
What is an anonymous structure or union?
-
Difference between
->
and.
operators?
🔄 9. Type Qualifiers & Casting
-
What is
const int*
,int const*
,int* const
? -
What is implicit vs explicit typecasting?
-
How to typecast void pointer?
-
Can we cast one structure to another?
-
Write a
typedef
for function pointer.
🧵 10. Multithreading & Concurrency (Embedded Focused)
-
What is a race condition?
-
How to avoid race conditions?
-
Difference between
mutex
andbinary semaphore
? -
How to create a thread in Linux using
pthread_create()
? -
How to share data between threads safely?
-
What are
mutex
,semaphore
, andspinlock
? -
Is
malloc()
thread-safe? -
Can we interrupt a thread?
-
How to cancel a thread?
🐞 11. Debugging & Tools
-
What is
gdb
? -
How to debug segmentation fault in C?
-
What are
nm
,readelf
, andobjdump
? -
What is use of
strace
andltrace
? -
How does
valgrind
help? -
What are
-Wall
,-g
,-O0
,-O2
,-static
flags? -
What is difference between
make
andgcc
? -
How does
make
resolve dependencies? -
What are
core dumps
and how to analyze them?
💡 12. Miscellaneous & Tricky
-
Can
main()
be called recursively? -
Can we write
main()
asint main(void)
? -
Can we assign a value to
const int
using a pointer? -
What is undefined behavior? Give 3 examples.
-
What is sequence point?
-
What is endianess?
-
How to check little/big endian in C?
-
What is use of
offsetof()
macro? -
What is interrupt handling? Can it be written in C?
-
What happens if we overflow the stack?
-
Can we modify return address in stack?
-
What is a segmentation fault vs bus error?
-
What is a trap instruction?
-
How does the kernel call user
main()
? -
Can
printf()
be thread-safe? -
Difference between dynamic and static libraries?
-
Can we allocate memory in
.text
segment?
🔁 13. Recently Added Extensions
-
Can structure have a static member?
-
Can we modify a constant global using pointer?
-
Difference between shallow and deep copy?
-
Difference between union and bit-fields?
-
Implement singly linked list reversal in C.
-
What is the output of
++*p++
? -
How to use
offsetof()
with alignment? -
What happens when you free a pointer twice?
-
What is memory alignment and padding?
-
Can we declare a variable with same name as function?