1 / 7

Data Types

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 + - / * %

elvis
Download Presentation

Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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}

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

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

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

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

  6. Characters Internal Representation ‘A’ (65)10 (01000001)2 ‘B’ (66)10 (01000010)2 … ‘a’ (97)10 (01100001)2 ‘b’ (98)10 (01100010)2 …

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

More Related