|
Datatypes |
There are 4 basic data types used in C :
integer
floating point
double precision
character
|
Integer |
Any positive or negative number without a decimal point.
Examples of valid integer constants are :
3 -20 +890 -3896
Integers may be signed (having a leading + or -) or not signed .
Not allowed with integer:
commas
decimal points
special symbols
Examples of invalid integers
$23.09 2,456 3.0
Compilers have limits on the largest and smallest integer values that can be used .These limits are implementation dependant ;they depend on how much storage each compiler sets aside for an integer .
|
Floating point and Double Precision Numbers |
Any signed or unsigned numbers having a decimal point.
Examples
+12.121 5. -4.9 0.0
Not allowed
commas
special symbols
Examples if invalid numbers
5,324.88 24 $56.4
Most computers use twice amount of the storage for double precision numbers than for floating point numbers.
Exponential Notation
Floating point and double precision numbers can be written in exponential notation which is commonly used to express either very large or very small numbers in a compact form.
Examples
|
Decimal Notation |
Exponential Notation |
|
1234. |
1.234e3 |
|
54321. |
5.4321e4 |
|
0.00987 |
9.87-e3 |
|
.000215 |
2.15-e4 |
The letter e stands for exponent .The number following the e represents a power of 10 and indicates the number of places the decimal point should be moved to obtain the standard decimal value.
|
Character |
Characters are letters of the alphabet (uppercase and lowercase) , the ten digits 0 through 9 and special symbols such as + %$ # @ !* .
A single character is any one letter ,digit or special symbol enclosed by single quotes .
Examples are
'A' '#' 'b' 'Y' '!'
Character constants are typically stored in a computer using either the ASCII ( ASK-KEY ) or ANSI (ANN-SEE) codes .
ASCII stands for American Standard Code for Information Interchange.
ANSI stands for American National Standards Institute is an extended set of 256 codes , the first of which are the same as the ASCII codes .
Each of these codes assigns individual characters to a specific pattern of 0's and 1's.
|
Letter |
Code |
|
a |
01100001 |
|
b |
01100010 |
|
c |
01100011 |
Using the ASCII code the sequence of characters 'a' ,'b' , 'c' requires 3 bytes of storage .
|
01100001 |
01100010 |
01100011 |
|
a |
b |
c |
Escape Sequences
The combination of a backslash and a specific characters.
When a backslash ( \ ) is used in front of a selected group of characters , the backslash tells the compiler to escape from the way these characters would normally be interpreted .
Each of these combination have only one character code .
|
Escape Sequence |
Name |
Meaning |
|
|
Alert |
Produces an audible or visible alert. |
|
|
Backspace |
Moves the cursor back one position (non-destructive). |
|
|
Form Feed |
Moves the cursor to the first position of the next page. |
|
|
New Line |
Moves the cursor to the first position of the next line. |
|
|
Carriage Return |
Moves the cursor to the first position of the current line. |
|
|
Horizontal Tab |
Moves the cursor to the next horizontal tabular position. |
|
|
Vertical Tab |
Moves the cursor to the next vertical tabular position. |
|
|
|
Produces a single quote. |
|
|
|
Produces a double quote. |
|
|
|
Produces a question mark. |
|
|
|
Produces a single backslash. |
|
|
|
Produces a null character. |
|
Data Types (32-bit) Type Length Range |
|||
| data type | bits | from | to |
| unsigned char | 8 | 0 | 255 |
| char | 8 | -128 | 127 |
| short int | 16 | -32,768 | 32,767 |
| unsigned int | 32 | 0 | 4,294,967,295 |
| int | 32 | -2,147,483,648 | 2,147,483,647 |
| unsigned long | 32 | 0 | 4,294,967,295 |
| enum | 16 | 2,147,483,648 | 2,147,483,647 |
| long | 32 | -2,147,483,648 | 2,147,483,647 |
| float | 32 | 3.4 x 10-38 | 3.4 x 10+38 |
| double | 64 | 1.7 x 10-308 | 1.7 x 10+308 |
| long double | 80 | 3.4 x 10-4932 | 1.1 x 10+4932 |
| near (pointer) 32 bits not applicable | |||
|
far (pointer) 32 bits not applicable |
|||