Integer Types
The integer type
is used for storing whole numbers. We can use signed, unsigned or plain integer
values as follows:
signed int index = 41982;
signed int temperature = -32;
unsigned int count = 0;
int height = 100;
int balance = -67;
Like characters,
signed integers can hold positive or negative values, and unsigned integers can
hold only positive values. However, plain integer can always hold positive or
negative values, they're always signed.
You can declare
signed and unsigned integer values in a shortened form, without the int
keyword:
signed index = 41982;
unsigned count = 0;
Integer values
come in three sizes, plain int, short int and long int.
int normal = 1000;
short int smallValue = 100;
long int bigValue = 10000;
The range of
values for these types will be defined by your compiler. Typically a plain int
can hold a greater range than a short int, a long int can hold a greater range
than a plain int, although this may not always be true. What we can be sure of
is that plain int will be at least as big as short int and may be greater, and
long int will be at least as big as plain int and may be greater. A short
integer is guaranteed to be at least 16 bits and a long integer at least 32
bits.
You can declare
short and long integer values in a shortened form, without the int keyword:
shortsmallValue = 100;
longbigValue = 10000;
You can have
long and short signed and unsigned integers, for example:
unsigned long bigPositiveValue =
12345;
signed short smallSignedValue= -7;
No comments:
Post a Comment