RSS2.0

Looking Something??



[C Programming Language] C Simple Data Types

Thursday, February 14, 2008

Primitive Data Types


C has five primitive data types :

  1. int : used to define integer numbers

  2. char : contains ASCII Code character (128 characters)

  3. float : used to define floating point numbers

  4. double : used to define big floating point numbers

  5. 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.

  • short

  • long

  • signed

  • unsigned


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 specifierBitsBytesMinimum valueMaximum value
signed charsame81−128+127
unsigned charsame810255
charone of the above81−128 or 0+127 or 255
shortsigned short int162−32,768+32,767
unsigned shortunsigned short int162065,535
intsigned int16 or 322 or 4−32,768 or
−2,147,483,648
+32,767 or
+2,147,483,647
unsignedunsigned int16 or 322 or 4065,535 or
4,294,967,295
longsigned long int324−2,147,483,648+2,147,483,647
unsigned longunsigned long int32404,294,967,295
long longsigned long long int648−9,223,372,036,854,775,808+9,223,372,036,854,775,807
unsigned long longunsigned long long int648018,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: