Arista · CS Fundamentals
Explain C printf pointers and memory layout
TrueInterview
October 7, 2026 · 1 min read
You are given the following C code:
const char *c = "12345";
Answer the following (assume a typical modern 64-bit Linux/macOS environment with GCC/Clang, except where behavior is undefined or implementation-defined):
- For each item below, what is it meant to print, and what actually occurs?
printf("%s", c);printf("%d", c);printf("%c", c);printf("%c", *c);printf("%c", *(c+1));- What is the proper way to print the address held in
c?
- Explain how you would use
gdb/lldbto examine:- the value of
c(as an address) - the bytes located at that address
- the string beginning at that address
- the value of
- Memory and allocation fundamentals:
- Compare
malloc/freewithnew/deletein C/C++ (initialization, constructors/destructors, type safety, failure behavior, arrays, etc.). - Describe what usually resides in the stack, heap, data/BSS, and text (code) segments. Where does a string literal such as
"12345"usually reside? Overview: This question tests understanding of C pointer semantics, printf format-specifier behavior, memory layout and allocation differences, and practical debugger use for inspecting addresses and bytes, within the Software Engineering Fundamentals domain.
- Compare
Loading comments…