Derived Data Types of C++ | Secondary Data Types of C++ 

Derived Data Types of C++ 

Derived Data Types of C++ | Secondary Data Types of C++ 



What is Data type ?

Data type gives the type and range of values that can be stored in a variable in C++. Different types of data types are

DERIVED DATA TYPES OF C++

Derived data types are those which are derived from primary data types. Different types of derived data types are:

i. Array

It is a collection of values having same size, type and range of values under single name .

They are of following types:

i. One Dimensional Array : Array having one dimension is known as one dimensional array.  It contains one subscript.

Example: int numr[10];

ii. Two Dimensional Array : Array having two dimensions is known as two dimensional array It contains two subscripts.

Example:  int num[3][3];

iii. Multidimensional Array: Array having more than two dimensions is known as multidimensional array It contains more than two subscripts.

Example: int num[2][2][2];

ii. Function

It is defined as named block of code. Functions is of two types:

Library Function

They are inside header files. They are prebuilt in C++.

User Defined Function

These functions are created by the programmer as per his own requirements.

iii. Pointer

It is basically used to store the address of another variable.

There are two operators used with pointers:”

i. * (Pointer to)

ii. & (Address of)

iv. REFERENCE

A reference is an alternative name for an object.

The syntax for declaring a reference variable is:

<Type>   &ref=   var;

Type is a valid data type of C++.

var refers to a variable.

ref refers to the reference variable.

//Program to demonstrate the use of reference.

#include<iostream>
using namespace std;
int  main()
{
int var=10;
int &ref=a;       //Reference variable b points to another variable a.
cout<<"\nvar="<<var;
cout<<"\nref="<<ref;
cout<<"\n&a="<<&var;
cout<<"\n&b="<<&ref;
var++;
cout<<"\nvar="<<var;
cout<<"\nref="<<ref;
return  0;
}

Output:

var=10
ref=10
&var=0x61fe14
&ref=0x61fe14
var=11
ref=11

v. const :

The keyword const can be used to declare a named constant. Its value can't be changed in program.
Example 
const int a=10;



Spread the love
Lesson tags: Derived Data Types of C++, Secondary Data Types of C++, What is a Data type in C++
Back to: C++ Programming Notes
Spread the love