Skip to content
FollowtheDamnCode

Constants and Keywords

Values that never change, and words C reserves for itself.

3 minute read

Big idea

A constant is a value that can never change. A keyword is a word C keeps for itself.

The idea

Put const in front of a variable and it becomes read-only:

const float PI = 3.14;
PI = 4;   // ✗ error: PI is read-only

Keywords are words with a special meaning in C — like int, float, if, for, return, and const. You can't use them as variable names.

Example

Try it — edit it and run it again
#include <stdio.h>

int main(void) {
    const int DAYS_IN_WEEK = 7;
    int weeks = 3;
    printf("%d\n", DAYS_IN_WEEK * weeks);
    return 0;
}
output
21

Run and edit it in the app.

Constants are often written in CAPITALS so they're easy to spot.

Think of it like

A printed price tag vs a whiteboard. A variable is the whiteboard — you can erase it and write again. A constant is printed — it stays the same.

🕷️ Spidey-sense: Some rules never change — like Aunt May's: home by dinner. A const is a value you promise never to change, and C stops you if you try. Keywords like int and return belong to C — you can't use them as names.

Common mistake

Using a keyword as a name:

int return = 5;   // ✗ return is a keyword
int result = 5;   // ✓

Key terms

  • Constant — A value that can't change after it's set.
  • const — Makes a variable read-only.
  • Keyword — A word reserved by C, like int, if, or return.

Check yourself

What happens if you try to change a const variable?

Which of these is a C keyword?

Can you name a variable int?