Primitive Data Types
C has five primitive data types :
- int : used to define integer numbers
- char : contains ASCII Code character (128 characters)
- float : used to define floating point numbers
- double : used to define big floating point numbers
- bool : used to define two conditions --> true or false / 1 or 0
Example Variable Initialisation:
1. int
int tes;
tes = 5;
2. char
char answer = 'x';
3. float
float score = 85.3;
4. double
double height = 1,6782992;
5. bool
bool check = true;
Modifiers
The three data types above have the following modifiers.
The modifiers define the amount of storage allocated to the variable. ANSI has the following rules :
short int <= int <= long int
float <= double <= long double
Implicit specifier(s) | Explicit specifier | Bits | Bytes | Minimum value | Maximum value |
---|---|---|---|---|---|
signed char | same | 8 | 1 | −128 | +127 |
unsigned char | same | 8 | 1 | 0 | 255 |
char | one of the above | 8 | 1 | −128 or 0 | +127 or 255 |
short | signed short int | 16 | 2 | −32,768 | +32,767 |
unsigned short | unsigned short int | 16 | 2 | 0 | 65,535 |
int | signed int | 16 or 32 | 2 or 4 | −32,768 or −2,147,483,648 | +32,767 or +2,147,483,647 |
unsigned | unsigned int | 16 or 32 | 2 or 4 | 0 | 65,535 or 4,294,967,295 |
long | signed long int | 32 | 4 | −2,147,483,648 | +2,147,483,647 |
unsigned long | unsigned long int | 32 | 4 | 0 | 4,294,967,295 |
long long | signed long long int | 64 | 8 | −9,223,372,036,854,775,808 | +9,223,372,036,854,775,807 |
unsigned long long | unsigned long long int | 64 | 8 | 0 | 18,446,744,073,709,551,615 |
Qualifier
1. Const
The const qualifier is used to tell C that the variable value can not change after initialisation.
For example, const float pi=3.14159;
So, the value of 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.
For example, #define PI 3.14159
2 . Volatile
volatile means the storage is likely to change at anytime and be changed but something outside the control of the user program. This means that if you reference the variable, the program should always check the physical address (ie a mapped input fifo), and not use it in a cashed way.
(www.space.unibe.ch)
0 comments:
Post a Comment