The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Constant variable, does not change its value during the execution of a program. A constant is a data value written by a programmer. Constants may be belonging to any of the data type(int, float, char). There are 4 basic types of constants. They are
A Decimal integer constants consist of any combination of digits from 0 to 9. A Decimal integer constants can contain two or more digits, but first digit should not be 0. Base value of decimal integer is 10.
| 0 | 12 | 856 | 456844 |
| 45,565 | invalid character (,) |
| 25.0 | invalid character(.) |
| 1 2 3 | invalid character(blank space) |
| 12-23-34-456 | invalid character(-) |
| 051 | first digit cannot be a zero |
An Octal integer should starts with 0 in order to identify the constant as an octal integer number. An Octal integer constants consist of any combination of numbers between 0 to 7. Base value of Octal integer constants is 8.
| 0 | 012 | 0856 | 0456844 |
| 4725 | does not starts with 0 |
| 01491 | invalid digit(9) |
| 012.23 | invalid character(.) |
| 051-43 | invalid character(-) |
A Hexadecimal integer constants can be a combination of any numbers in the range of 0 to 9 and a to f or A to F. Here A to F denotes 0 to 15. A Hexadecimal integer constants should starts with either 0x or 0X. Base value of Hexadecimal integer constants is 16.
| 0x | 0X12 | 0x8A6 | 0x4a84b4 |
| 4725 | does not starts with 0x |
| 0x1H9 | invalid charcter(H) |
| 0X12.23 | invalid character (.) |
| 0X51-43 | invalid character(-) |
Unsigned or Long Integer Constants may exceed the range of Integer. Unsigned or Long Integer Constants are identified by the suffix u or l. Here
| 4541U | unsigned int |
| 4558L | long int |
A floating point constant consist of integer part, decimal point and fractional part. A floating point constant contains exponential field e or E followed by an integer. A normal decimal point value will be treated as double until a suffix f is added to the decimal point value. Decimal point value using double will be more accurate than float. Adding suffix l or L to the Decimal point value will be treated as long double. A floating point constant with an exponent is essentially the same as scientific notation, except that base 10 is replaced by e or E. Exponential notation is useful in representing the numbers whose magnitudes are very large or very small.
| Valid Floating Point Constants | Invalid Floating Point Constants |
|---|---|
| 47.00 | 47 |
| 0.4 | 0 5 |
Consider the number 257.47. This can also be return as 0.25747E3. The sequence of digits after decimal point (25747) is a mantissa. The power of E (3) is known as exponent.
| Valid Exponential notation | Invalid Exponential notation |
|---|---|
| 542.254E6 | 7.5.3E4 |
| 542.254e6 | 7.5.3e 4 |
A character constant is a single character enclosed within single quotes ' '. A character constant also represented with a single digit or a single special character or white space enclosed within a single quotes. All PC make use of ASCII(American Standard Code for Information Interchange) character set, where each integer character is numerically encoded. A character constant occupies a single byte.
| Valid Character Constants | Invalid Character Constants |
|---|---|
| 'a' | 'ab' |
| '1' | '22' |
A string constant is a sequence of characters enclosed within double quotes " ". The Characters may consists of letters, digits, escape sequences and spaces. A string constant always ends with null (/0). A string constant occupies a two bytes.
| Valid String Constants | Invalid String Constants |
|---|---|
| 'Hello Programmer' | 'Hello Programmer" |
| "Hello Programmer" | "Hello Programmer' |
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019