REAL CONSTANT –
Real constants or floating point Constants are numeric constants that contain decimal point.
Some Valid Floating point constants are :
Generally, for expressing very large or very small real constants, we use exponential (scientific) form. Here, we write the number in mantissa and exponent form, which gets separation by ‘e‘ or ‘E‘.
The mantissa can be an integer or real number, while the exponent can be only an Integer(Positive or negative)..
For example, we can write the number 1500000 as 1.5e6, here 1.5 is mantissa and 6 is the exponent. Some more examples are,
- 3300000000 – 3.3e9
- 0.0000053 – 5.3e-6
- -780000 – (-6.7E5)
Furthermore, by default the type of a floating point constant is double. Also, we can explicitly mention the type of constant by suffixing it with a f_or_F( for float_type). And, l or L(for long_double). For example,
Floating point constant of type double..
- 2.8e-91 or 2.8e-9L
Floating point constant of type long double..
- 3.25f or 3.25F
Floating point constant of type float..
CHARACTER CONSTANT –
Generally, we can define a Character Constant as a single character that encloses within single quotes.
Some of the examples of valid Character Constants are –
- ‘ ‘
Some examples of Invalid Character Constants are –
It is invalid because there should be only one character within quotes.
It is invalid because we can’t allow double quotes.
- ‘ ‘
It is invalid because no character is present between single quotes.
It is invalid because single quotes are missing.
Furthermore, there’s a unique integer value which associates with every character constant. This unique integer is the numeric value of the character in the machine’s character code.
For example, if the machine is using ASCII (AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE). Then, the character ‘A‘ represents Integer value 65 and character ‘1‘ represents value 49.
Some ASCII values are as follows –
- A – Z ASCII VALUE (65 – 90)
- a – z ASCII VALUE (97 – 122)
- 0 – 9 ASCII VALUE (48 – 57)
- ; ASCII VALUE (59)
STRING CONSTANT –
If we talk about String Constants, they have zero, one or more than one Character. These are the constants having more than one character. Generally, a string constant encloses between double quotes (” “).
Also, one important point is that the compiler places ‘\0’ automatically at the end of the string. ‘\0’ is a null Character which the compiler places at the end of every string to declare the end of the string.
Some examples of string constants are –
- “MUKUL BHATT”
- ” “
NOTE : “A” and ‘A’ are different, because the first one is a string constant which contains character A and \0. While the other one is a character constant which represents Integer value 65.
Thus, it was all about THE C DATATYPES AND CONSTANTS…
For more information regarding other C ELEMENTS Posts..Click on,