Home   MosaicPresentation format
<http://cnfolio.com/IntroToComputingTopic02Print>
Introduction to Computing – B142L

Data types

Academic year 2011/12



Objectives:
  1. Basic data types in the C language
  2. Comparison of different data types






Digital data



A bit is the smallest unit of digital data. There are two possible values:

A combination of multiple bits can be used to store and encode more complex and useful data.






Binary encoding of numeric data



The sum of binary encoded bits can be used to represent integer (whole number) values.








Binary encoding of characters



ASCII (American Standard Code for Information Interchange) is a standard for using binary encoding to represent character symbols.

ASCII uses 8 bits to encode 128 characters:

Part of the table of ASCII codes:



Source: ASCII. (2011). Retrieved from http://en.wikipedia.org/wiki/Ascii






Basic data types



There are 3 basic data type categories in the C language.
  1. void
  2. integer
    • char = 1 byte
      • unsigned char
    • short = 2 bytes
      • unsigned short
    • int = 4 bytes
      • unsigned int
    • long = 8 bytes
      • unsigned long
  3. floating point
    • float = 4 bytes = 6 digits of decimal precision
    • double = 8 bytes = 15 digits of decimal precision
    • long double = 16 bytes = 18 digits of decimal precision






Basic data types



Data type indicates:
  1. The amount of memory to allocate, and
  2. How to interpret the bits of data stored at the allocated location in memory

Data types increases portability of software between different hardware.

They are reserved keywords in C.






Data variables



A data variable has:
  1. an identifier
  2. a data type
  3. a data value









Identifiers in the C language



Identifiers are user friendly names of variables, functions and constants. They are case sensitive and have no length restrictions. However, they must follow these rules:






Boolean values



The C language does not have a data type for boolean values of true and false. Instead, it uses the following rules:






Review questions




Data types


What is the decimal value of the binary number below?

High order   0 0 1 1 0 0 1 0   Low order

50
76
77
51
Average rating is  






Review questions




Data types


Which is not a valid data type keyword in the C language?

integer
short
double
float
Average rating is  






Review questions




Data types


Which is not a basic data type category in the C language?

floating point
double
integer
void