Pages

Saturday, 25 June 2011

Basis data types



The range of different types of data that a programming language can handle is one of the factors that determines the power of the programming language. C language is very powerful in this sense. Almost all types of data can be represented and manipulated in C program.

Inside a digital computer, at the lowest level, all data and instructions are stored using only binary digits.(0 and 1). Thus, decimal number 65 is stored as its binary equivalent: 0100 0001. Also the character "A" is stored, as binary equivalent of 65(A's ASCII): 0100 0001. Both the stored values are same but represent different type of values. How's that?

Actually, the interpretation of a stored value depends on the type of the variable in which the value is stored even if it is just 0100 0001 as long as it is stored on the secondary storage device. Thus, if 0100 0001 is stored in an integer type variable, it will be interpreted to have integer value 65, whereas, if it is stored in character type of variable, it will represent "A".

Therefore, the way a value stored in a variable is interpreted is known as its data type. In other words, data type of a variable is the type of data it can store.
Every computer language has its own set of data types it supports. Also, the size of the data types (number of bytes necessary to store the value) varies from language to language. Besides, it is also hardware platform dependent.

C has a rich set of data types that is capable of catering to all the programming requirements of an application. The C-data types may be classified into two categories: Primary and Composite data types as shown in Figure

C has two distinct categories of data types - primary, and composite. Primary data types are the ones that are in-built with C language while composite data types allow the programmers to create their own data types.
There are five primary data types in C language.
1.Char: stores a single character belonging to the defined character set of C language.
2.Int : stores signed integers, e.g., positive or negative integers.
3.Float : stores real numbers with single precision (precision of six digits after decimal points).
4.Double : stores real numbers with double precision, i.e., twice the storage space required by float.
5.Void : specify no values.

The following table shows the meaning and storage spaces required by various primary data types.

Data Type Qualifiers

Primary C data types may have different sizes that enable them to store large range of values. This is indicated in a program by appending a keyword before the data type - called data type qualifier.

For instance, short, long, signed and unsigned are data type qualifiers for int basic type. Thus an integer type data may be defined in C as short int, int, unsigned int, long int. The range of values and size if these qualified data-types is implementation dependent. However, short is smaller than or equal int, which in turn, is smaller than long. Unsigned int contains larger range since it does not store negative integers.

Also known as derived data types, composite data types are derived from the basic data types. They are 5 in number.
1.array: Sequence of objects, all of which are of same types and have same
name, e.g.: int num [5];
Reserves a sequence of five locations of 2 bytes, each, for storing integers num[0], num[l], num[2], num[3] and num[4].
2.pointer: Used to store the address of any memory location.
3.structure: Collection of variables of different types e.g.: A structure of employee's data, i.e., name, age, salary.
4.union: Collection of variables of different types sharing common memory space.

5.Enumerated: Its members are the constants that are written as identifiers
Though data type they have signed integer values. These constants represent values that can be assigned to corresponding enumeration variables.
Enumeration may be defined as
enum tag {memberl, member2 .... member n);
e.g.: enum colors { red, green, blue, cyan};
colors foreground, background;

The first line an enumeration named "colors" which may have any one of the four colors defined in the curly braces. In the second line, variables of the enumerated data type "colors" are declared.

c programmming online,basic of c language,structure of c programming,c language statements,Compiling a C Program,Pseudo Codes in c,basis data type in c ,variables in C Program,constants in C Program,c operators in C Program,special operators in C ,Decision Making,Branching & Looping in C Program,if statement in C Program,for loop in C Program

No comments:

Post a Comment