Friday, May 16, 2008

Secondary Data Type

1. Array:

It is a collection of data of similar data type.
e.g. Int num [5];

Reserve a sequence of 5 location of two bytes each for storing integers.

2. Pointer:

Pointer is a variable that stores the address of some other variable.
e.g. int *i;

The above statement declares i as pointer to integer data type.

3. Structure:

A structure is a collection of data of different data types under one name.
e.g.
Struct employees
{
char Name[10];
int Age;
int Salary;
}

4. Union:

It is a collection of data of different types sharing common memory space.
e.g. Union item

{
int m;
float x;
char c;
} ;

5. Enumerated Data types:

This data types gives us an opportunity to invent your own data type and define what values the variable of this data type can take.
Example: enum colors

{
red, green, blue, cyan
};
colors foreground, background;

Here the declaration has two parts:

a) The first part declare the data type and specifies its possible values.
b) The second part declare variable of this data type.

Now we can give the values to these variables:

foreground=red;
background=blue;

But remember we can't use values that aren't in the original declaration. Thus, the following declaration cause error.

foreground=yellow;

Note: Secondary data type has been given in detail later.

0 comments:

Copyright

Copyright © 2008 C Tutorial, All rights are reserved