Constants in C (continued…)


Constants in C (continued…)

Link to previous post on constant 


Floating point constants :
        Floating pont constants is decimal number that represents a signed real number.
The representation of a floating-point constant an integer portion and a decimal portion or an exponent portion(or both).

Example:
·       0.2
·       827.156
·       500.
·       1.
·       0.00034
·       2E-8
·       0.06e-3
·       1.6667E+8.1212312e12

Floating point constants has a much greater range than integer constants.

The range of floating point is grom 3.4E-38 to 3.4E+38.
Floating point constants are of type float,double,long.
Example :
·       100L(has type long double)
·       100F(has type float)
·       100D(has type double)
A floating point constant with out F or L in suffix is of type double.


Character Constants :
        A character constant is a single character , enclosed with in single quotation mark.
        Example :
·       ‘a’
·       ‘D’
·       ‘3’
·       ‘$’
Character constants have integer values that are determined by the computers particular character set .most computers makes use of ASCII character set, In which each individual character is numerically encoded.
Example:
Constant
Value
‘A’
65
‘x’
120
‘3’
51
‘$’
36
 
32



Character Strings:
A character string or a string constant consist of any number of consecutive characters(including null) enclosed in double quotation marks.
Example :
·       “green”
·       “India”
·       “Hello reader ….”
·       “Dhoni 7 ”
·       “$22.50”
Since a string can be of any length the end of string is marked as ‘\0’ (null character),having ASCII value of 0.
Note that character constant ‘a’ and string constant “a” are not equivalent .

Lets discuss about escape sequences (it comes under character constants) to chin our next post….
Thank you ….

Constants in C


Constants  in  C :
C has four basic type of constants
·       Integer constants
·       Floating point constants
·       Character constants
·       String constants


Integer Constant :
        An integer constant is an integer valued number. Thus, it consist of sequence of numbers .
        Integer constants can be written in three different number system :
·       Decimal(base 10)
·       Octal(base 8)
·       Hexadecimal(base 16)
·       Binary(base 2)

A decimal integer consist of any combination of digits taken from set 0 to 9.
Example of valid decimal integer constants :
·       0
·       1
·       743
·       32767  etc.
An octal number constant can consist of digits taken from set 0 to 7.
The first digit must be 0 in order to identify the number as octal.
Examples of octal integer constants:
·       01
·       0743
·       077777   etc.
A hexa decimal integer constant must begin with either 0x or 0X .
It can be followed by any combination of digits taken from set 0 t0 9 and A to F.
Examples of hexadecimal integer constant :
·       0x
·       0X1
·       0X7FFF
·       0xabcd    etc…
The magnitude of integer constants range from zero to some maximum value.the typical max value is 32767 .
The unsigned integer constant can be identified by appending the letter U or u to the end of the constant.
Example :
·       5000U(decimal unsigned)
·       077777U(octal unsigned)
·       0X50000U(hexadecimal unsigned)
Long integer constants can be identified by letter L or l at the end of constant.
Example:
·       123456789L(decimal long)
·       0123456L(octal long)
An unsigned long integer can be identified by appending the letter UL to end of constant.
Example:
·       12345678UL(decimal unsigned long)
·       0XFFFFFUL(hexadecimal unsigned long)


Lets continue the other constant types in the next post….
Thank you ….



Popular Posts