NCERT Computer: Chapter 7 – Introduction to C + + Part 8

Download PDF of This Page (Size: 183K)

2 Explicit Conversion

It is also called type casting. It temporarily changes a variable data type from its declared data type to a new one. It may be noted here that type casting can only be done on the right hand side of the assignment statement.

Initially variable salary is defined as float but for the above calculation it is first converted to double data type and then added to the variable bonus.

9 Constants

A number which does not charge its value during execution of a program is known as a constant.

  • Literals

  • Integer Numerals

  • Floating Point Numerals

  • Character and string literals

Any attempt to change the value of a constant will result in an error message. A constant in C++ can be of any of the basic data types.

const qualifier can be used to declare constant as shown below:

The above declaration means that Pi is a constant of float types having a value 3.1415.

Examples of valid constant declarations are:

10 Variables

A variable is the most fundamental aspect of any computer language.

Image of Variables in C++

Image of Variables in C++

Image of Variables in C++

Variable are used in C++, where we need storage for any value, which will change in program.

It is a location in the computer memory which can store data and is given a symbolic name for easy reference.

The variables can be used to hold different values at different values at different times during the execution of a program.

To understand more clearly we should study the following statements:

For example, a variable Total of type float can be declared as shown below:

float Total;

Similarly the variable Net can also be defined as shown below:

Examples of valid variable declarations are:

(i) int count;

(ii) int i, j, k;

(iii) char ch, first;

(iv) float total, Net;

(v) long int sal;