Tuesday 3 March 2015

Data Types in C


A data type in a programming language is a set of data with values having predefined characteristics such as integers and characters. The language usually specifies the range of values for a given data


type, how the values are processed by the computer and how they are stored. Storage representations and machine instructions to handle data types differ form machine to machine. The variety of data types available allows the programmer to select the type appropriate to the needs of the application as well as the machine. C supports a number of data types; if they are not enough programmers can also define their own data types. C supports three classes of data types:

1. Primitive (or basic) data types – these are the fundamental data types supported by the language. These can be classified as integer types, floating point types and character types.

2. User defined data types – based on the fundamental data types users can define their own data types. These include type defined data types (using typedef keyword) and enumerated types (using enum keyword).

3. Derived data types – programmers can derive data types such as arrays, structures, unions and pointers by combining several data types together.


2.5.1 Primitive Data Types

The C language supports five primitive data types; namely integers (int) floating point numbers (float), double precision floating point numbers (double), characters (char) and void (void). Many of these data types can be further extended as long int and long double. Each of these data types requires different storage capacities and has different range of values depending on the hardware (see Table 2.3). Character (char) type is considered as an integer type and actual characters are represented based on their ASCII value.



2.5.2 Modifiers

The basic data types can be modified by adding special keywords called data type modifiers to produce new features or new types. The modifiers are signed, unsigned, long and short. For example short int represents fairly small integer values and require half the amount of storage as regular int numbers. Except with void type, the modifiers can be used with all the basic data types as shown in Table 2.4.







No comments:

Post a Comment