On this page
Control Flow & Functions
Prev: Syntax, Types & Operators | Up: fundamentals | Next: Arrays & C Strings
Rel: Control Flow & Composition, Build Pipeline & Linking
Ref: cppreference — C Functions
Tags: #public #prog #c #fundamentals
Contents
Prototypes, Pass-by-Value & static Linkage
- Declare public function prototypes in
.hheaders and mark file-private helpersstaticso they have internal linkage (invisible to other translation units). - Always write
(void)for zero-parameter functions in C11/C17 (int init(void);), becauseint init();historically meant unspecified parameters. - All C arguments are passed by value — to mutate caller state or avoid copying large structs, pass a pointer (
T *orconst T *).
static int clamp_int(int v, int lo, int hi) {
if (v < lo) return lo;
if (v > hi) return hi;
return v;
}
Storage Duration
- Automatic (default local variables): lives on the call stack until block exit.
- Static (globals and
staticlocals): zero-initialized beforemain(), lives for the entire program. - Allocated (
malloc/calloc/realloc): lives on the heap untilfree().
Linked from
Related notes
- tuts/c/fundamentals Linked here; links to this page; shared tags: #c, #fundamentals, #prog
- tuts/c/fundamentals/arrays_and_strings Linked here; links to this page; shared tags: #c, #fundamentals, #prog
- tuts/c/fundamentals/syntax_types_and_operators Linked here; links to this page; shared tags: #c, #fundamentals, #prog
- tuts/c/builtins/static links to this page; shared tags: #c, #prog
- tuts/c/compilation_and_internals/build_pipeline_and_linking Linked here; shared tags: #c, #prog
- tuts/programming/foundations/control_flow_and_composition Linked here; shared tags: #prog
- tuts/c/fundamentals/structs_unions_and_enums shared tags: #c, #fundamentals, #prog
- tuts/c shared tags: #c, #prog
- tuts/c/builtins shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #c, #prog