C & C++ fundamentals / 04
Variables and types
An introduction to int, float, double, char, and the rules for naming variables.
On this page
Variables come in several types, including integers, floating-point numbers, and characters. The basic declarations are int for integers, float or double for floating-point values, and char for characters.
Basic types
The original lesson uses the following common sizes and approximate characteristics:
| Type | Memory | Range or characteristic |
|---|---|---|
int | 4 bytes | −2,147,483,648 to +2,147,483,647; stores integers |
float | 4 bytes | About 6 significant digits; the original lists approximately 3.4E−38 to 3.4E+38 |
double | 8 bytes | About 15 significant digits; the original lists approximately 1.7E−308 to 1.7E+308 |
char | 1 byte | Stores a character-sized value |
Editorial note: sizes and ranges are implementation-dependent. The floating-point ranges in the original table are rough approximations, not the exact minimum and maximum values. Use the implementation's limits when precision matters.
Naming variables
A variable name cannot begin with a digit. For example, 6num is not a valid name. Use letters and underscores, with digits permitted after the first character; other punctuation is not generally allowed in ordinary identifiers.
Names are case-sensitive, so uppercase and lowercase letters are distinct. Avoid reserved names and collisions with library functions such as those declared in stdio.h.
Most importantly, choose a name that communicates the variable's purpose. Meaningful names make the program easier to understand.
Moved here from Tistory
I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.
The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.
Original post on Tistory English edition · Aug 30, 2026