Community
Basic types and operators in C
C provides a standard, minimal set of basic types.Sometimes those
are called "primitive" types.More complex data structures can be
built up from these basic types.
Integer Types
The "integral" types in "C" form a family of integer types.They all behave like integers and can be mixed together and used in a similar ways.The differences, are due to the different number of bits ("widths") used to implement each type - - the wider types can store greater ranges of values.
char ASCII character - - at least 8 bits.Pronounced "car". As a practical matter char is basically always a byte which is 8 bits which is enough to store a single ASCII character.8 bits provies a signed range of -128..127 or an unsignes range is 0..255. char is also required to be the "smallest addressable unit" for the machine -- each byte in memory has its own address.
short Small integer -- at leat 16 bits which provides a signed range of -32768..32767.Typical size is 16 bits.Not used so much.
int Default integer -- at least 16 bits, with 32 bits being typical.Defined to be the "most comfortable" size for the computer. If you do not care about the range for an integer variable, declare it int since that is likely to be an appropriate size (16 to 32 bits) which works for that mahine.
long Large integer-- at leats 32 bits.Typical size is 32 bits which gives a signed range of about -2 billion...+2 billion. Some compilers support "long long" for 64 bit ints.
The details about char, int, floats and doubles will be given in the next lesson which will be published soon.
Feel free to post any queries regarding this lesson.
Integer Types
The "integral" types in "C" form a family of integer types.They all behave like integers and can be mixed together and used in a similar ways.The differences, are due to the different number of bits ("widths") used to implement each type - - the wider types can store greater ranges of values.
char ASCII character - - at least 8 bits.Pronounced "car". As a practical matter char is basically always a byte which is 8 bits which is enough to store a single ASCII character.8 bits provies a signed range of -128..127 or an unsignes range is 0..255. char is also required to be the "smallest addressable unit" for the machine -- each byte in memory has its own address.
short Small integer -- at leat 16 bits which provides a signed range of -32768..32767.Typical size is 16 bits.Not used so much.
int Default integer -- at least 16 bits, with 32 bits being typical.Defined to be the "most comfortable" size for the computer. If you do not care about the range for an integer variable, declare it int since that is likely to be an appropriate size (16 to 32 bits) which works for that mahine.
long Large integer-- at leats 32 bits.Typical size is 32 bits which gives a signed range of about -2 billion...+2 billion. Some compilers support "long long" for 64 bit ints.
The details about char, int, floats and doubles will be given in the next lesson which will be published soon.
Feel free to post any queries regarding this lesson.