0Pricing
C Academy · Lesson

Characters as Integers

ASCII values.

Characters as Integers is a free C Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Characters Are Numbers

In C, a char is just a small integer. Every character has a numeric value defined by the ASCII table.

The letter 'A' is stored as the number 65, 'B' is 66, and so on.

#include <stdio.h>

int main(void) {
    char c = 'A';
    printf("The character %c has value %d\n", c, c);
    return 0;
}

Printing the ASCII Value

Use the %d format specifier to print a char as its integer value, and %c to print it as a character.

The same variable can be viewed both ways.

#include <stdio.h>

int main(void) {
    char letter = 'z';
    printf("As char: %c\n", letter);
    printf("As int:  %d\n", letter);
    return 0;
}

Digits Have Codes Too

The character '0' is not the number 0. It has ASCII value 48.

The digit characters '0' to '9' sit at codes 48 to 57 in order.

#include <stdio.h>

int main(void) {
    printf("'0' = %d\n", '0');
    printf("'9' = %d\n", '9');
    return 0;
}

Char to Digit Conversion

Because digits are contiguous, you can convert a digit character to its numeric value by subtracting '0'.

'7' - '0' equals 7.

#include <stdio.h>

int main(void) {
    char d = '7';
    int value = d - '0';
    printf("The digit value is %d\n", value);
    return 0;
}

Arithmetic on Characters

Since chars are integers, you can do math on them. Adding 1 to 'A' gives the code for 'B'.

This works because the alphabet letters are contiguous in ASCII.

#include <stdio.h>

int main(void) {
    char c = 'A';
    char next = c + 1;
    printf("After A comes %c\n", next);
    return 0;
}

Looping Through the Alphabet

You can loop from 'a' to 'z' using a char as the loop counter.

The loop compares character codes just like numbers.

#include <stdio.h>

int main(void) {
    for (char c = 'a'; c <= 'z'; c++) {
        printf("%c", c);
    }
    printf("\n");
    return 0;
}

The Case Gap

Uppercase and lowercase letters are 32 apart in ASCII. 'a' is 97 and 'A' is 65.

So 'a' - 'A' equals 32.

#include <stdio.h>

int main(void) {
    printf("'A' = %d\n", 'A');
    printf("'a' = %d\n", 'a');
    printf("Gap = %d\n", 'a' - 'A');
    return 0;
}

Manual Case Conversion

Knowing the gap is 32, you can convert lowercase to uppercase by subtracting 32.

This is exactly what toupper does under the hood.

#include <stdio.h>

int main(void) {
    char lower = 'm';
    char upper = lower - 32;
    printf("%c becomes %c\n", lower, upper);
    return 0;
}

Special Characters

Control characters also have codes. The newline '\n' is 10, tab '\t' is 9, and the null terminator '\0' is 0.

The space character is 32.

#include <stdio.h>

int main(void) {
    printf("newline = %d\n", '\n');
    printf("tab     = %d\n", '\t');
    printf("space   = %d\n", ' ');
    return 0;
}

Char Holds Small Numbers

A char typically holds values from -128 to 127 (signed) or 0 to 255 (unsigned).

You can store small integers directly in a char.

#include <stdio.h>

int main(void) {
    char small = 100;
    small = small + 5;
    printf("small = %d\n", small);
    return 0;
}

Building a Caesar Shift

Combining these ideas, a simple Caesar cipher shifts each letter by a fixed amount using character arithmetic.

Here we shift one letter forward by 3.

#include <stdio.h>

int main(void) {
    char c = 'x';
    char shifted = 'a' + (c - 'a' + 3) % 26;
    printf("%c shifted by 3 = %c\n", c, shifted);
    return 0;
}

Quick Check

Test your understanding of characters as integers.

Recap

You learned that in C:

  • A char is a small integer holding an ASCII code.
  • %c prints it as a character, %d as a number.
  • Digits '0'-'9' and letters are contiguous, enabling arithmetic.
  • c - '0' converts a digit char to its value, and the case gap is 32.

Frequently asked questions

Is the “Characters as Integers” lesson free?

Yes — the full text of “Characters as Integers” is free to read here on the web, and the C Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.

What will I learn in “Characters as Integers”?

ASCII values. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Characters as Integers” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Characters as Integers
  2. The ctype Library
  3. Reading Characters
  4. Building Char Utilities
← Back to C Academy