numeric types — concept C23
Numeric types have implementation-dependent ranges and representations; use `limits.h`, `float.h`, or `stdint.h` types and check overflow before conversion and arithmetic.
CKTIS / C
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Numeric types have implementation-dependent ranges and representations; use `limits.h`, `float.h`, or `stdint.h` types and check overflow before conversion and arithmetic.
A C object is storage with a type, lifetime, and representation; reading requires a live object and a permitted access type. Structure assignment copies fields, but pointer fields remain shallow references.
Performance depends on algorithmic complexity, memory locality, allocation count, and target; preserve correctness first, then measure a representative workload. A micro-optimization based on undefined behavior is a bug.
The preprocessor handles inclusion, macros, and conditional compilation before C parsing; a macro argument may be expanded more than once. Function-like macros need parentheses, unique internal names, and side-effect-free arguments.
Check whether an integer is prime by testing divisors only up to its square root. In C, the condition `d <= n / d` checks that bound without risking overflow from multiplication.
In a hosted environment execution begins at `int main(void)` or the `argc`/`argv` form; `argc` is nonnegative and `argv[argc]` is a null pointer. Returning from the initial `main` is equivalent to `exit`, and the status is delivered to the environment.
`struct` groups named members, `union` shares storage among members, and arrays hold one element type; designated initializers reduce order dependence, but padding and layout must not be assumed without an ABI.
Recursion calls a function on a smaller problem until a base case; no progress causes endless calls, and C guarantees neither tail-call elimination nor stack-exhaustion detection.
A reduction folds a sequence into one value; sums and statistics must handle empty input, choose an accumulator that avoids overflow, and account for floating-point rounding error.
Round-robin scheduling gives ready jobs CPU time in turn, for at most one time quantum each. The C example simulates this policy and calculates waiting time and turnaround time under an explicit arrival-ordering rule.
Scope controls name visibility while lifetime controls object existence; a pointer may remain in scope after its object expires, but dereferencing it is undefined.
A security boundary validates lengths, ranges, encoding, and authorization before using external data; fixed format strings, checked size arithmetic, and ordered cleanup reduce overflows and memory errors.
A sliding window maintains one contiguous array range and moves its boundaries without recomputing every sum. The shrinking variant relies on nonnegative input values.
Sorting requires a consistent ordering relation; a `qsort` comparator returns negative, zero, or positive and should not subtract integers when subtraction may overflow. `qsort` does not guarantee stability.
A C string is a `char` array terminated by the first `\0` byte; length excludes the terminator, but the buffer must reserve space for it. String functions do not know capacity, so a missing terminator or undersized destination causes access outside an object.
`assert` checks an invariant in debug builds but `NDEBUG` may remove it; tests must separately cover boundaries, failures, and resources.
C distinguishes calendar `time_t`, processor `clock_t`, and `timespec`; conversions can fail, while time zone, daylight changes, and resolution depend on the environment.
Conversions apply promotions and type changes; narrowing may lose value, out-of-range signed conversion is implementation-defined, and a pointer cast repairs neither alignment nor validity.
The C type system distinguishes compatible types, qualifiers, and an object’s effective type; incompatible pointer access can violate aliasing, and `const` restricts modification through that lvalue rather than always making storage immutable.
For undefined behavior the standard imposes no requirements; unspecified behavior chooses an allowed possibility, while implementation-defined behavior must be documented. A test must never depend on an observed UB result.
A variable is a declared object with a type, scope, and storage duration; an uninitialized automatic variable may hold an indeterminate value whose read can be undefined. Initialize before first read and keep scope narrow.
EOF is a macro from <stdio.h>, used by functions such as fgetc to signal end-of-file or a read error.
The EXIT_SUCCESS and EXIT_FAILURE macros from <stdlib.h> portably signal program success or failure.
Macros from <limits.h> describe an implementation's integer ranges and widths. Use them instead of assuming an 8-bit byte or a 32-bit int.