Basic Types

Generally, use int for integer values and double for floating point. The char type is one byte long for holding characters, but it is really just a small integer, holding an ASCII value. Note that characters in Java are Unicode, but C is an older language, where the char type is limited to 256 values.

C has several more basic types than Java does, in various sizes:

Integer Types: charshort intintlong intlong long int
Unsigned Integer Types: unsigned charunsigned short intunsigned intunsigned long intunsigned long long int
Floating Types: floatdoublelong double

Unlike Java, sizes are not dictated by the standard, but by the compiler writer. The only restrictions are that char should be one byte, and, reading left to right, the sizes should never get smaller. They may be the same, though.

Pretty reliably, int and float will be four bytes, short int two and double eight. The long double type may be 12 or 16. For a long time, long int was also four bytes, but now eight is usual. The long long type is usually eight.

The unsigned types take only non-negative values. By using the sign bit to extend the magnitude, they can hold values twice as large as the maximum signed type of same size, but they can be problematic to use.

Generally, integer types other than int itself may be written with just the qualifiers. That is, you may write long int as long.

The basic types support the usual operations familiar from Java: +-*/%, and the shortcut versions like += and ++.

If you need an integer of a specific size, you may #include the header cstdint, which declares types such as int16_t and int32_t, which are exactly 2 or 4 bytes, respectively. There are several others.

[way more info]