70 likes | 283 Views
Data Types. A data type is a set of values and a set of operations defined on these values Example: boolean type (not provided in C) Values={true, false} Operations={and, or, not}. Integers. Examples: 2, 4567, 0, -100, 10200 Operations + - / * %
E N D
Data Types • A data type is a set of values and a set of operations defined on these values • Example: boolean type (not provided in C) Values={true, false} Operations={and, or, not}
Integers • Examples: 2, 4567, 0, -100, 10200 • Operations + - / * % • There are several types: int, long, unsigned, … • Int values are in the interval [-32768, 32767] • Long values are in [-2147843648, 2147483647] • Size might differ between different compilers, OSs, Machines • Size of int = 2 bytes in Borland C++ • Size of int = 4 bytes in Visual C++ • Size of long = 4 byts • Size of unsigned = 2 bytes • Examples of integer values: population, number of odd values in a certain range
Real Numbers • Examples 2.23 4567.9 0 -100.1 3.449 • There are 2 types float, double • Size of float = 4 bytes • Size of double = 8 bytes • float values can be large 3.4X1038 • float values can be small 3.4X10-38 • double values can be very small 1.7X10-308 and can be very large 1.7X10308 • values are often expressed using e notation. Examples: 2.3e+58 1.38888e-101 -4.5e200 • Example of real value: average of values
Characters • Character data type is indicated by char • Size of char value = 1 byte • inside the program, char values are enclosed between single quotations • Examples ‘a’ ‘b’ … ‘z’ ‘A’ ‘B’ … ‘Z’ ‘0’ ’1’ … ‘9’ ‘>’ ‘<’ ‘+’ ‘%’ ‘@’ ’?’ ‘/’ ‘\n’ new line character ‘\t’ tab character ‘\a’ alert or beep ‘\’’ single quote ‘\”’ double quote ‘\\’ inverted slash
Characters Cont. • Comparisons can be performed on characters: ‘A’ <‘B’< … <‘Z’<…< ‘a’ <‘b’ … <‘z’ • Characters are sorted according to their order in the ascii code table • Some ascii codes ‘A’ 65 ‘B’ 66 … ‘Z’ 90 ‘a’ 97 ‘b’ 98 …’z’ 122
Characters Internal Representation ‘A’ (65)10 (01000001)2 ‘B’ (66)10 (01000010)2 … ‘a’ (97)10 (01100001)2 ‘b’ (98)10 (01100010)2 …
Strings • Strings are used to represent names of entities • A string is a sequence of characters enclosed between double quotations • Examples “ali” “Nablus” “PO Box 3300” “10423456”