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

Post on 03-Jan-2016

220 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

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

Explicit Type Cast

• You can explicitly cast data types as well.

• See typecast.c

Character Types

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

• See printASCII.c

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

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

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];

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

top related