cisc105 – general computer science class 9 – 07/03/2006

10
CISC105 – General Computer Science Class 9 – 07/03/2006

Upload: sydney-barker

Post on 03-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CISC105 – General Computer Science Class 9 – 07/03/2006

CISC105 – General Computer Science

Class 9 – 07/03/2006

Page 2: CISC105 – General Computer Science Class 9 – 07/03/2006

Numeric Data Types

• Integer can be represented by various data types in C and are stored as binary values– int (16 bits – 15 bits for value 1 for sign):

-32,767 to 32,767 – unsigned (16 bits): 0 to 65,535– long (32 bits – 31 for value, 1 for sign):

-2,147,483,647 to 2,147,483,647– unsigned long (32 bits): 0 to 4,294,967,295

Page 3: CISC105 – General Computer Science Class 9 – 07/03/2006

Numeric Data Types

• Floating-point Types are stored in memory by using a mantissa and exponent value such that real_number = mantissa x 2exponent

– float : 10-37 to 1038 with 6 significant digits– double: 10-307 to 10308 with 15 significant

digits– long double: 10-4931 to 104932 with 19

significant digits– See doublePrecision.c doublePrecision2.c

Page 4: CISC105 – General Computer Science Class 9 – 07/03/2006

Automatic Data Type Conversion

• int + double; returns a double• double = int; the int is converted to

a double• int = double; the double is

converted to an int and the fractional part is lost

• See datatypeConversion.c

Page 5: CISC105 – General Computer Science Class 9 – 07/03/2006

Explicit Type Cast

• You can explicitly cast data types as well.

• See typecast.c

Page 6: CISC105 – General Computer Science Class 9 – 07/03/2006

Character Types

• The char data type can be represented as a character or by it’s ASCII numeric value.

• See printASCII.c

Page 7: CISC105 – General Computer Science Class 9 – 07/03/2006

Enumerated Types

• An enumerated type is a list of values that is specified by the programmer in type declaration

• Enumeration constant is an identifier that is one of the values of the enumerated type.

• See enumeratedTypes.c

Page 8: CISC105 – General Computer Science Class 9 – 07/03/2006

Arrays

• An array is a collection of values of the same type.

• An array is a Data Structure– Data Structure – is a composite of related

data items stored under the same name

Page 9: CISC105 – General Computer Science Class 9 – 07/03/2006

Declaring Arrays

• An Array is declared by listing the type variable_name[number_of_elements]– int grades[5];– double income_for_month[12];– char name[15];

Page 10: CISC105 – General Computer Science Class 9 – 07/03/2006

Accessing Elements

• To access the elements in an array you use the array name and the subscript– grade[1];– income_for_month[5];– See array1.c array2.c