Constant is a value that can not be changed during execution of program.
Integer constants :
- Consists of numeric digits .
- An integer constant must have at least one digit.
- It can have positive ( + ) or negative ( - ) sign, but the default sign is positive.
- Other than a positive or negative sign, it can not have any special character like decimal point, comma or blank space.
1. Decimal constants : Decimal number system uses numbers from 0 to 9 . In decimal integer constant first digit can not be 0. For example : 3000, 289 etc.
2. Octal constants : Octal number system uses numbers from 0 to 7. In octal integer constant first digit must be 0. For example : 0300, 0275 etc.
3. Hexadecimal constants : Hexadecimal number system uses numbers from 0 to 9 and character from A, B, C, D, E, F, a,b,c,d,e,f. In hexadecimal integer constant first two characters should be 0x or 0X.. For example : 0XA15C, 0xFFA , 0xbe etc.
Real Constants :
Real constants are also called floating point constants. Real constants could be written in two forms :
1. Fractional form
2. Exponential form
1. Fractional Form :
1. Fractional Form :
- A real constant must have at least one digit.
- It must have one and only one decimal point.
- It can have a positive or negative sign but the default sign is positive.
- Other than positive or negative sign and a decimal point, a real constant can not have any special character.
- Examples : + 325.34 , 426.0 , -32.75
2. Exponential form :
- A real constant in this form has two parts - mantissa and exponent.
- The mantissa and exponent part should be separated by a letter E or e .
- The mantissa part may have positive or negative sign but the default sign is positive.
- The exponent must have at least one digit , which must be a positive or negative integer. Default sign is positive.
- Range of real constants expressed in exponential form is -3.4E38 to 3.4E38.
- Example : 3.2E-5 , -0.61e-5 etc.
Character constants :
A character constant is single alphabet , a single digit or a single special symbol enclosed within single inverted commas.The maximum length of character constant can be one character. For example : 'A' , '@' , '9' etc.
0 Comments