The definition of a variable will assign storage for the variable and define the type of data that will be held in the location.
So what data types are available?
int | float | double | char | void | enum |
Please note that there is not a boolean data type. C does not have the traditional view about logical comparison, but thats another story.
Recent C++ compilers do have a boolean datatype.
{ int Count; Count = 5; } |
{ float Miles; Miles = 5.6; } |
{ double Atoms; Atoms = 2500000; } |
{ char Letter; Letter = 'x'; } |
Type Bytes Bits Range |
short int 2 16 -16,384 -> +16,383 (16kb) unsigned short int 2 16 0 -> +32,767 (32Kb) unsigned int 4 16 0 -> +4,294,967,295 ( 4Gb) int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) long int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) signed char 1 8 -128 -> +127 unsigned char 1 8 0 -> +255 float 4 32 double 8 64 long double 12 96 |
These figures only apply to todays generation of PCs. Mainframes and midrange machines could use different figures, but would still comply with the rule above.
You can find out how much storage is allocated to a data type by using
the sizeof operator.
const float pi=3.14159;
pi cannot be changed at a later time within the program.
Another way to define constants is with the
#define preprocessor which
has the advantage that it does not use any storage (but who counts bytes
these days?).
Qualifiers
See also:
Data type conversion
typedef keyword.
Top | Master Index | Keywords | Functions |