The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
What is Constant Variable?
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
- Integer Constant.
- Floating Point Constant.
- Character Constant.
- String Constant.
- An integer constants consists of sequence of Integer numbers from 0 to 9.
- Decimal points, black spaces, commas cannot be included within an integer constants.
- An Integer constants can either be positive or negative or zero.
- The number without sign can be assumed as positive
- Integer constants can be classified into 3 ways . They are
- Decimal Integer Constants.
- Octal Integer Constants.
- Hexadecimal Integer Constants.
Decimal Integer Constants
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.
Valid Decimal integer Constants in C Programming
Invalid Decimal Integer Constants
||invalid character (,)
|1 2 3
||invalid character(blank space)
||first digit cannot be a zero
Octal Integer Constants
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.
Valid Octal Integer Constants in C Programming
Invalid Octal Integer Constants
||does not starts with 0
Hexadecimal Integer Constants
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.
Valid Hexa Integer in C Programming
Invalid Hexa Integer Constants in C Programming
||does not starts with 0x
||invalid character (.)
Unsigned or Long Integer Constants
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
- u represents unsigned int.
- L represents long int.
Example of unsigned and long integer constants
Floating point constant
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 and Invalid Floating Point Constants
|Valid Floating Point Constants
||Invalid Floating Point Constants
What is Mantissa and Exponent?
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 and Invalid Exponential notation
|Valid Exponential notation
||Invalid Exponential notation
Character Constants in C Programming
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 and Invalid Character Constants
|Valid Character Constants
||Invalid Character Constants
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 and Invalid String Constants
|Valid String Constants
||Invalid String Constants
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.