char

A char is a variable type that represents a single character or “glyph”.

Under the hood, C represents each char as an integer (its “ASCII value”).

Lowercase letters are 32 more than their uppercase equivalents (bit flip!)

char uppercaseA = 'A';// Actually 65
char lowercaseA = 'a';// Actually 97
char zeroDigit = '0’;// Actually 48
// prints out every lowercase character
for (char ch = 'a'; ch <= 'z'; ch++) {
    printf("%c", ch);
}

Common ctype.h Functions

FunctionDescription
isalpha(ch)true if chis ’a’through ‘z’ or ’A’through ‘Z’
islower(ch)true if chis ’a’through ‘z’
isupper(ch)true if chis ’A’through ‘Z’
isspace(ch)true if chis a space, tab, new line, etc.
isdigit(ch)true if chis ’0’through ‘9’
toupper(ch)returns uppercase equivalent of a letter
tolower(ch)returns lowercase equivalent of a letter

Remember: these returnthe new char, they cannot modify an existing char!

String Length

terminate every string with a ‘\0’ character.

Caution: strlen is O(N) because it must scan the entire string!
Save the value if you plan to refer to the length later.

C Strings As Parameters

When you pass a string as a parameter, it is passed as a char *. C passes the location of the first character rather than a copy of the whole array.

Common string.h Functions