Constant in C++

Constant are also known as Literals.They are fixed. We cannot change them. for example


a is variable. we assign  a value 10.10 is constant we cannot change it.But we change the variable name like a,b,c.vlue cannot change .It is fixed.There are many types of constant like

1. Integer constant

2. Float and Double constant

3. Char constant

4. String constant

1. Integer constant:An integer constant consists of digits.If it starts from a Zero,it is an octal integer constant,otherwise it is a decimal integer.example

const int y=4;

2. Float and double constant:Both float and double are used for representing real values and differ only in precision .These constants have an integral part,a decimal part and an optional signed exponent.example

float d=12.6;

double g=453.9;

3. Char constant:    A character constant is a single  character written within quotes,as in ‘x’ .for example:

const char ch=’y’;

4. String constant : A String constant is a constant which written within double

quotes,as in “x” .for e.g

const string  s1= “Garry”;


Comments are closed.