Pick a topic — languages & databases — 100+ questions and answers in the center column.
C
Pointers, memory, UB, preprocessor, standard library.
102 questions
Question 1
Low-level procedural language close to hardware; manual memory, minimal runtime; used for OS, embedded, and performance-critical systems.
Example code
#include <stdio.h>
int main(void) { puts("C"); return 0; }Question 2
A variable holding a memory address of another object; * dereferences, & takes address of an lvalue.
Example code
int x = 42;
int *p = &x;
printf("%d\n", *p);Question 3
A pointer guaranteed to compare unequal to any valid object pointer; dereferencing is undefined behavior.
Example code
int *p = NULL;Question 4
The standard imposes no requirements—compilers may optimize assuming UB never happens; bugs can be non-deterministic.
Example code
// signed overflow is undefinedQuestion 5
Compiler must document choice (e.g. int size); differs by platform but must be consistent per implementation.
Example code
// int may be 32-bitQuestion 6
Local auto variables often on stack; malloc allocates heap; lifetime and size differ—stack overflow vs heap exhaustion possible.
Example code
int a;
int *h = malloc(sizeof *h);Question 7
malloc uninitialized bytes; calloc zero-initializes; realloc resizes possibly moving the block—check return pointer.
Example code
void *m = malloc(16); memset(m, 0, 16); free(m);Question 8
Only pointers from malloc family; double-free and use-after-free are UB—set pointer to NULL after free if needed for clarity.
Example code
free(p); p = NULL;Question 9
Accessing invalid memory (often via bad pointer); OS kills process; debug with core dumps and sanitizers.
Example code
// segfault: *NULLQuestion 10
Variables can't be assigned after init; const pointers have mutable vs const data distinctions—read declarations right-to-left.
Example code
const int c = 3;Question 11
Prevents certain optimizations for memory-mapped hardware or signal handlers—misused for thread communication (wrong).
Example code
volatile int *mmio = (int *)0xDEADBEEF;Question 12
Single instance for function lifetime, initialized once—storage duration is program/static, not auto.
Example code
void f(void) { static int s = 0; s++; }Question 13
Internal linkage—symbol not visible to other translation units.
Example code
static void helper(void) {}Question 14
Declares symbol defined elsewhere—linker resolves across object files.
Example code
extern int g;Question 15
A preprocessed source file compiled to one .o—one compilation unit.
Example code
// one .c file = one translation unitQuestion 16
Declarations shared via #include; include guards or #pragma once prevent redefinition.
Example code
#ifndef H_H
#define H_H
void h(void);
#endifQuestion 17
inline suggests inlining; static gives internal linkage—common pattern for header-defined helpers in C.
Example code
static inline int add(int a, int b) { return a + b; }Question 18
Padding inserted for alignment; offsetof and #pragma pack affect layout—ABI sensitive across compilers.
Example code
struct S { char c; int i; }; // paddingQuestion 19
Overlapping members share storage—size is max member; type punning has strict aliasing rules.
Example code
union U { int i; float f; };Question 20
Integer constants; underlying type implementation-defined until C99 improvements—don't assume size without checks.
Example code
enum E { A, B };Question 21
Creates aliases for types—readability for structs and function pointers.
Example code
typedef struct Node Node;Question 22
Callbacks and vtable-like patterns; syntax is verbose—typedef helps.
Example code
int (*cmp)(const void *, const void *);Question 23
Library binary search and quicksort with comparator void*—must return negative/zero/positive consistently.
Example code
qsort(a, n, sizeof *a, cmp);Question 24
Unbounded string functions risk overflows; prefer strncpy strncat with care or safer abstractions.
Example code
char buf[4]; snprintf(buf, sizeof buf, "%d", 123);Question 25
Bounded formatting into buffer; returns what would have been written—check truncation.
Example code
unsigned u = UINT_MAX; u++; // wrapsQuestion 26
Signed overflow is UB in C; unsigned wraps defined—use safe math libraries for security code.
Example code
unsigned char u = 255; int x = u; // promotedQuestion 27
Smaller ints promote to int in expressions—surprising results mixing signed/unsigned.
Example code
if (a & 1) {}Question 28
& vs &&, | vs ||—mixing up causes subtle bugs and sometimes UB with side effects.
Example code
char bytes[4]; memcpy(bytes, &x, sizeof x);Question 29
Accessing an object through incompatible type is UB—char* is special exception for byte access.
Example code
void foo(int *restrict a, int *restrict b);Question 30
Promises no other pointer aliases the same object—enables optimizations; lying is UB.
Example code
printf("%d", va_arg(ap, int));Question 31
va_list, va_start, va_arg, va_end—caller/callee must agree on types; easy to corrupt stack if wrong.
Example code
#include <signal.h>
void h(int s) {}Question 32
Non-local jumps bypass stack unwinding—dangerous with modern invariants; avoid in C++ mixed code.
Example code
if (fopen("f", "r") == NULL) perror("open");Question 33
Async handlers limited to async-signal-safe functions; prefer masking and polling self-pipe pattern.
Example code
printf("> "); fflush(stdout);Question 34
Thread-local error indicator for library calls—must save before other calls if needed.
Example code
int c = getchar(); if (c == EOF) {}Question 35
stdout line-buffered when tty; fflush after prompts; setvbuf controls policy.
Example code
#define MAX(a,b) ((a)>(b)?(a):(b))Question 36
Macro int negative value distinct from valid unsigned char stream values—store in int not char when reading.
Example code
#if defined(__linux__)
#endifQuestion 37
Text substitution—parenthesize parameters; prefer const/inline enums when possible.
Example code
static int x; // internal linkageQuestion 38
ifdef tests defined symbol; if evaluates expressions—use for feature tests carefully.
Example code
#include <errno.h>
if (remove("ghost.txt") != 0) perror("remove");Question 39
External (default globals), internal (static), none (automatic locals)—affects symbol visibility to linker.
Example code
FILE *fp = fopen("data.txt", "r");
if (fp) { setvbuf(fp, NULL, _IONBF, 0); fclose(fp); }Question 40
Pointers to const document read-only views—helps APIs communicate mutation intent.
Example code
void print(const int *p);Question 41
Last struct member [] without size—alloc struct+extra bytes; C99 feature for variable-length tail storage.
Example code
struct H { size_t n; int d[]; };
// malloc(sizeof(struct H) + n*sizeof(int))Question 42
Temporary objects (C99) with lifetime scope rules—useful for small structs passed by value.
Example code
int *p = (int[]){1,2,3};Question 43
struct s = { .x = 1 }—clearer and order-independent initialization.
Example code
struct S s = { .x = 1, .y = 2 };Question 44
C11 allows unnamed members for ergonomic overlays in embedded structs.
Example code
struct { int a; int b; } s;Question 45
Control and query alignment requirements for SIMD or hardware structs.
Example code
_Alignas(16) char buf[64];
printf("%zu", _Alignof(int));Question 46
Compile-time assertions—catch broken assumptions early.
Example code
_Static_assert(sizeof(int) >= 4, "int too small");Question 47
threads.h optional; real code often uses pthreads on POSIX for portability.
Example code
// thrd_create / or use pthreadsQuestion 48
POSIX threads: mutex, cond, join—pair every create with join or detach to avoid leaks.
Example code
pthread_t t;
pthread_create(&t, NULL, start, NULL);
pthread_join(t, NULL);Question 49
Normal, recursive, error-check—choose per deadlock risk; avoid locking order cycles.
Example code
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&m);Question 50
Always wait in a loop checking predicate—spurious wakeups are allowed.
Example code
pthread_cond_wait(&c, &m);Question 51
Lock-free atomics in C11 where supported—use for counters and flags, not complex invariants alone.
Example code
_Atomic int x;
atomic_store(&x, 1);Question 52
C11 atomics have memory_order seq_cst default; relaxed/acquire/release for performance experts only.
Example code
atomic_load_explicit(&x, memory_order_acquire);Question 53
Prevent reordering around critical sections—prefer proper atomics or mutexes.
Example code
// asm volatile("" ::: "memory");Question 54
Does not synchronize threads—use atomics or mutexes; volatile is for hardware/signals.
Example code
// use atomics instead of volatile for syncQuestion 55
AddressSanitizer finds use-after-free, buffer overflows—compile and link with -fsanitize=address.
Example code
// gcc -fsanitize=addressQuestion 56
UndefinedBehaviorSanitizer catches shifts, signed overflow assumptions—great in CI debug builds.
Example code
// gcc -fsanitize=undefinedQuestion 57
MemorySanitizer for uninitialized reads—slower, use selectively.
Example code
// clang -fsanitize=memoryQuestion 58
memcheck for heap errors without recompile—heavy runtime cost.
Example code
// valgrind ./a.outQuestion 59
-g enables source-level debugging; split-dwarf reduces link memory.
Example code
// gcc -gQuestion 60
Smaller binaries; hide internals—keep unstripped builds for crash analysis.
Example code
// strip a.outQuestion 61
clang-tidy, cppcheck catch many C bugs before runtime.
Example code
// cppcheck --enable=all .Question 62
Coding standard for safety-critical embedded—subset restricts risky constructs.
Example code
// follow MISRA rules in embeddedQuestion 63
Secure coding rules—focus on integer and string handling.
Example code
// CERT C secure patternsQuestion 64
Build dependencies; pattern rules; parallel -j—still common for small C projects.
Example code
all:
gcc -O2 -o app main.cQuestion 65
Meta-build generates Make/Ninja—cross-platform C/C++ standard.
Example code
cmake -S . -B build && cmake --build buildQuestion 66
Fast low-level build format—CMake can target it for quicker incremental builds.
Example code
ninja -C buildQuestion 67
pkg-config supplies cflags/libs for dependencies—integrate in build scripts.
Example code
pkg-config --cflags --libs libpngQuestion 68
SONAME versioning; rpath/runpath; dlopen for plugins—ABI breaks require bump.
Example code
gcc -shared -fPIC -o libx.so x.cQuestion 69
Position-independent code for shared objects—small overhead on some architectures.
Example code
gcc -fPIC -c x.cQuestion 70
Allow default implementations overridable at link time—used in libc hooks.
Example code
__attribute__((weak)) void hook(void) {}Question 71
Control section placement for embedded targets—VMA/LMA for flash vs RAM.
Example code
// MEMORY { FLASH : ORIGIN = 0x08000000, LENGTH = 512K }Question 72
Memory-mapped I/O registers need volatile accesses—ordering may need barriers.
Example code
*(volatile uint32_t *)0x40000000 = 1;Question 73
CPU cache vs device visibility—flush/invalidate on architectures that need it.
Example code
// cache clean/invalidate before DMAQuestion 74
Network byte order htons/ntohs; file formats document endian—don't assume host order.
Example code
uint32_t h = htonl(0x01020304);Question 75
May trap or be slow on some CPUs—use memcpy for portable packed structs.
Example code
uint8_t b[4]; memcpy(&v, b, 4);Question 76
Implementation-defined layout—avoid for portable wire formats; use masks explicitly.
Example code
struct { unsigned a:3; unsigned b:5; } f;Question 77
Stored in read-only memory—modifying is UB; type should be const char*.
Example code
const char *s = "read-only";Question 78
int main(void) or int main(int argc, char** argv)—return 0 or EXIT_SUCCESS.
Example code
int main(int argc, char **argv) { return 0; }Question 79
Environment variables not thread-safe on some platforms if modified—treat as read-only after startup.
Example code
const char *h = getenv("HOME");Question 80
Not reentrant—use strtok_r with saved state in threaded code.
Example code
char *tok = strtok_r(line, " ", &save);Question 81
Directory iteration not necessarily thread-safe per DIR*—one DIR per thread.
Example code
struct dirent *e;
while ((e = readdir(d)) != NULL) {}Question 82
Copy-on-write process split; careful with threads—only async-signal-safe between fork and exec.
Example code
pid_t p = fork();
if (p == 0) { /* child */ }Question 83
Replace process image; file descriptors may need FD_CLOEXEC discipline.
Example code
execl("/bin/ls", "ls", NULL);Question 84
Map files or anonymous memory; MAP_SHARED for IPC; msync for persistence guarantees.
Example code
void *p = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, fd, 0);Question 85
IPC between processes or threads—nonblocking and event loops integrate with select/poll/epoll.
Example code
int fd[2]; pipe(fd);Question 86
Wait on fds with millisecond timeout—edge vs level triggered epoll nuances on Linux servers.
Example code
struct pollfd fds[1] = {{.fd=0,.events=POLLIN}};
poll(fds, 1, 1000);Question 87
Driver-specific operations—documented per device; errors easy to mishandle.
Example code
ioctl(fd, REQUEST, &arg);Question 88
POSIX makes errno thread-local—correct on modern libc for threaded servers.
Example code
// errno is thread-local on POSIXQuestion 89
Stack allocation dynamic—risk stack overflow; VLA similar cautions in C99.
Example code
int *p = alloca(n * sizeof *p);Question 90
Variable length arrays on stack—optional in C11; disabled on some embedded compilers.
Example code
int a[n]; // if compiler supports VLAQuestion 91
memcpy dst/src restrict expectation—memmove handles overlap correctly.
Example code
memcpy(dst, src, n); // no overlapQuestion 92
Legacy BSD; memmove is standard portable overlap-safe copy.
Example code
memmove(dst, src, n); // overlap-safeQuestion 93
Serialize integers portably by shifting bytes explicitly—don't cast struct pointers to char* for wire format without care.
Example code
uint32_t v; uint8_t b[4] = {0,0,0,1}; memcpy(&v,b,4);Question 94
Error detection on packets—table-driven implementations common in embedded.
Example code
// uint16_t crc = crc16_table[...]Question 95
Scaled integers on MCUs without FPU—careful with overflow and rounding.
Example code
int32_t q = (a * b) >> 8;Question 96
Pet in main loop or task scheduler—false trips vs hung detection tradeoff.
Example code
// IWDG->KR = 0xAAAA;Question 97
Dual-bank flash, checksum verify, rollback—state machine testing critical.
Example code
// verify CRC before swap banksQuestion 98
Linker sections .rodata—verify const actually lands in ROM on embedded link scripts.
Example code
const uint8_t rom[] __attribute__((section(".rodata")));Question 99
Worst-case stack depth tools for embedded—interrupt nesting counts.
Example code
// gcc -fstack-usageQuestion 100
Keep short; defer work; volatile flags—no malloc, limited printf.
Example code
void ISR_Handler(void) { flag = 1; }Question 101
ARM Cortex abstraction for vendors—standard register names and startup.
Example code
// NVIC_EnableIRQ(IRQn);Question 102
Vendor hardware abstraction—trade portability vs overhead vs direct registers.
Example code
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);