Data types
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
C's basic types and their usual size on modern computers:
| type | size | what it holds |
|---|---|---|
char |
1 byte | a character or a small number (-128…127) |
int |
4 bytes | a whole number (±2 billion) |
long long |
8 bytes | a big whole number |
float |
4 bytes | a fractional number, ~7 significant digits |
double |
8 bytes | a fractional number, ~15 digits — use this one |
The unsigned modifier removes the sign and doubles the upper limit: unsigned int goes from 0 to ~4 billion.
The sizeof operator tells you the size (the result has type size_t and is printed with %zu):
printf("%zu\n", sizeof(int)); // 4
printf("%zu\n", sizeof(double)); // 8
The sizes are not fixed by the standard: the standard only guarantees minimums. For example, long is 8 bytes on Linux x86-64, but 4 bytes on Windows and in WebAssembly. If you need an exact size, there are the types int32_t, int64_t (the "Fixed-size integers" lesson).
A char in C is just a small number. The character 'A' and the number 65 are the same thing:
char c = 'A';
printf("%c %d\n", c, c); // A 65
printf("%c\n", c + 1); // B
Task. Read a character and print its code and the character after it, separated by a space. For A: 65 B.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.