Fundamentally c only really accepts integers (signed and unsigned) as well as floats.
long:~ more space to store an integer short:~ less space to save memory
Here are all the non-trivial combinations
note, combinations like long signed int is the same as
long int
You may omit the int at the end as it is not mandatory.
By the spec, we need short <= int <= long but that
means we can have short = int = long
We can check the <limits.h> to determine the
ranges on your machine.
long long ints are a c99 feature
shorts hold between ±32, 768
chars hold 128 characters, and are 7-bit.
L:= The constant is of type long, as well as long
doubles. U:= Unsigned, can be used in combination with
L, like UL LL:= The constant is
of type long long.
floats can be represented in the following ways.
57.0 57. 570e0 57E0 5.7e1 5.7e+1 .57e2 570.e-1 // all are 57.0
F:= float constants. l
The exponent is the power of 10 that the number is scaled.
When the variable is asked to store a number larger than it can, an integer overflow happens. It has undefined behaviour with signed integers, but defined behaviour with unsigned. With unsigned we get the correct answer modulo 2n where n is the number of bits used to store the result.
Decimals must not begin with a 0. Octals must begin with
a 0 (this are base 8 numbers). Hexadecimals must begin with
a 0x
instead of %d use %u for base 10,
%o for octal, %x for hexadecimal.
for shorts, prepend with h, e.g. %hd,
%hu, %ho, %hx
for longs, prepend with l as for shorts, and long longs,
prepend with ll
floa := single precision floating point doubl
:= double precision floating point. Enough for most
programs. long doubl := Extended precision floating points.
Rarely needed.
In c99 we also have complex variants of float, double and long double.
Ascii is a 128 character set Latin-1 is a 256 character set
Characters are small integers. Use single quotes.
Look at the following UNPORTABLE code.
if ('a' <= ch && ch <= 'z'){
ch = ch - 'a' + 'A';
}
for (ch = 'A'; ch <= 'Z'; ch++) //iterate from A to ZIf you are using char to store a 256 bit integer, you may want to specify if it is unsigned or signed.