C Programming • C17 baseline, standards-specific features labeled
Variables, Initialization, and Constants
Initialize objects before reading them and use const to express values that should not be modified through a name.
A declaration gives an object a type and a name. Uninitialized automatic objects do not have a predictable value. Initialize them at declaration, and use const for inputs or configuration that a function should only read.
Example
#include <stdio.h>
int main(void) {
const double tax_rate = 0.08;
double subtotal = 25.00;
double total = subtotal * (1.0 + tax_rate);
printf("%.2f\n", total);
return 0;
}
What to expect
27.00
Key idea: Initialization and const-qualified interfaces make data flow easier to review.