Complete Computer Knowledge Portal

Tuesday, July 9, 2013

Derived Data Type in C++

The Data type that is derived from fundamental data types is called derived data type. Some of them are explained below:

 Array:  An array is a collection of homogeneous type of data. It is a named list of finite numbers of data elements. In array each data element is referenced by a set of consecutive numbers i.e. 1, 2, 3……n. If TECH is an array of five elements than its elements will be referenced as: TECH [1], TECH [2], TECH [3], TECH [4], TECH[5]. An Array can either be one dimensional, two dimensional or multidimensional.

Functions: Self contained block of program that performs a coherent task of some type is called Function. These are used because of following reasons:
1)It avoids writing of same code again and again because same function can be called in the main program again and again.
2)It makes programming simple because each module is written with specialized functions that makes debugging and testing easier.

Some Important points about Functions in C++
i)Every C++ Program consists of at least one function.
ii)If any C++ program contains only one function than that will be main() only.
iii)Program execution is always started from main().If there are more than one functions than one of them will be main().
iv)C++ Program may consist of any no. of functions.

Pointers: Pointer is a variable that contains the address of another variable. Variable that contains address of another variable is said to be pointing to second variable. Figure given below illustrates this concept.
















In This example A is a Pointer to B.

Reference: It is an alternative name for objects. Reference variable is used to provide alias for previously defined variable. Reference is declared as:
 type & reference_variable=variable_name;
type is its base type i.e. any valid  C++ data type, followed by ampersand symbol (&), a reference variable name that is equated to a previously defined variable.

Constants: Special keyword Cont is used to define an object as constant rather than variable.  The value of this defined constant can not be changed during the program execution. Constants are declared as follows:
Cont type name=value;                                e.g. Cont int a=5;
Constants must be initialized at the time of declaration.

No comments:

Post a Comment