Case sensitivity in C
What you'll learn: How the C compiler treats uppercase and lowercase letters as entirely different characters.
The picky librarian
Imagine you are visiting a very strict librarian. If you ask for a book titled "The Great Gatsby," they will walk to the shelf and hand it to you. However, if you ask for "the great gatsby" or "THE GREAT GATSBY," the librarian will stare at you blankly and claim the book doesn't exist.
In the eyes of the C compiler, the letter 'A' and the letter 'a' are as different as the number '5' and the letter 'Z'. They have different underlying codes in the computer's memory, so the compiler does not see them as related in any way.
Capitalization matters
In C, this rule applies to everything: the words built into the language (keywords), the names you give to your data (variables), and the names of your functions.
If you create a container for a number and name it Score, you cannot try to access it later by typing score or SCORE. The computer considers these three distinct names that could hold three completely different values.
Look at this example:
#include <stdio.h>
int main() {
int points = 10;
int Points = 50;
// This prints "10", because "points" is lowercase
printf("%d", points);
// This prints "50", because "Points" starts with a capital
printf("%d", Points);
return 0;
}
In the code above, points and Points coexist as two separate variables. While this is technically allowed, it is usually a bad idea because it makes your code very confusing for humans to read!
Keywords must be lowercase
Most of the "command words" in C, such as int, return, main, and if, are strictly lowercase. If you accidentally type Return or INT, your program will fail to compile. The computer will give you an error message because it doesn't recognize those capitalized versions as valid commands.
When you are debugging your code and see an "undefined" error, the first thing you should check is your shifting finger. A single accidental capital letter is one of the most common reasons for a program to break.
Key takeaway
C is case-sensitive; Apple, apple, and APPLE are three completely different things to the compiler.