Data types cont .....

Void

this is a place-holder. No memory space is allocated and nothing can be stored. This data type represents the absense of data - an empty set of values. void data type is used when one doesn't want any value from the function. Refer attachment for Basic Data Types!

Derived Data types

These data types are created according to the need of the user. These data types include array, functions, pointer, reference variable, constant, etc.

Array

An array is a data structure which allows a collective name to be given to a group of elements all of which have the same type. These locations are termed as elements of the array. all the elements of an array are of the same type.

An individual element of an array is identified by its own unique index ( or subscript). An array subscript, which is the number of elements in the arry surrounded by square brackets [ ].

An array declaration is very similar to a variable declaration. Firstly a type is given for the elements of the array, then an identifier for the array, within square brackets and the number of elements in the array, which should be an array.

For example: float annual_temp[10];

This declaration will cause will cause the compiler to allocate space for 10 consecutive float variables in memory. The figure below illustrates an array annual_temp of 10 elements:

0 1 2 3 4 5 6 7 8 9

Function

A function is a block of instructions that is executed when it is called from some other point of the program. It is a sub-program that performs some operations on data and returns a value. Functions can be built-in or user defined. The function main() is the calling function of the program which is executed automatically when a user-defined function is invoked.

The syntax for declaring a function is :

type name ( argument1, argument2, ....) statement

where:

type is the type of data returned by the function.

name is the name by which it will be possible to call the function.

arguments as many as wanted can be specified.

statement is the function's body. It can be a single instruction or a block of instructions. In the latter case it must be delimited by curly brackets.

For example

int addition( int a, int b)

{

int r;

r=a+b;

return(r);

}

HOME LEARN C++ PREVIOUS NEXT