Home › C Tutorial › C constants
C constants
Values that cannot change.
Use const to protect a variable. Write constant names in capitals by habit. #define makes a text replacement.
Commands in this lesson
const
Definition: Declares a variable that cannot be reassigned.
Syntax:
const name = value;
Example:
const pi = 3.14;
console.log(pi);Example code
#include <stdio.h>
#define MAX 100
int main() {
const float PI = 3.14;
printf("%.2f %d\n", PI, MAX);
return 0;
}