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 2 exponent –float : to with 6 significant digits –double : to with 15 significant digits –long double : to with 19 significant digits –See doublePrecision.c doublePrecision2.cdoublePrecision.cdoublePrecision2.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.cdatatypeConversion.c
Explicit Type Cast You can explicitly cast data types as well. See typecast.ctypecast.c
Character Types The char data type can be represented as a character or by it’s ASCII numeric value. See printASCII.cprintASCII.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.cenumeratedTypes.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.carray1.carray2.c