Beruflich Dokumente
Kultur Dokumente
A Review in C
Data Type
• an extensive system used for declaring
variables or functions of different types.
– NOTE: The type of a variable determines how
much space it occupies in storage and how the bit
pattern stored is interpreted.
Data Type: Types and Description
Types and Description
• Basic Type
• Enumerated Types
• The Type Void
• Derived Types
Basic Types
1. Integer Types
2. Floating-Point Types
3. Character type
Integer Type
• whole numbers
• Positive or negative
• int
– Ex: int id;
Integer Type
Type Storage size Value range
-32,768 to 32,767 or -2,147,483,648 to
int 2 or 4 bytes
2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned
2 bytes 0 to 65,535
short
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned
4 bytes 0 to 4,294,967,295
long
Integer Type
sizeof(type) - yields the storage size of the object or
type in bytes.
#include <stdio.h>
#include <limits.h>
int main() {
printf("Storage size for int : %d
\n", sizeof(int));
return 0; }
Floating-Point Type
• Can hold real numbers
• float/double
– Ex.: float accountBalance;
double bookPrice;
• can be represented in exponential form
– Ex.: float normalizationFactor =
22.442e2;
Floating-Point Type
Storage
Type Value range Precision
size
6 decimal
float 4 byte 1.2E-38 to 3.4E+38
places
2.3E-308 to 15 decimal
double 8 byte
1.7E+308 places
long 3.4E-4932 to 19 decimal
10 byte
double 1.1E+4932 places
Floating-Point Type
float.h - defines macros that allow you to use these values and other details
about the binary representation of real numbers in your programs.
#include <stdio.h>
#include <float.h>
int main() {
printf("Storage size for float : %d \n",
sizeof(float));
printf("Minimum float positive value: %E\n",
FLT_MIN );
printf("Maximum float positive value: %E\n",
FLT_MAX );
printf("Precision value: %d\n", FLT_DIG );
return 0; }
Character Type
- char
- Ex.: char test = 'h';
- Size = 1 byte
Void Type
indicates that no value is available.