What is Constants in C?
Constant is a value that cannot be changed during execution
of the program. Constant is user define value, which is input by the user and
cannot be changed during the program of execution.
There are three type of constants-
- Numeric Constants : Numeric Constants are those constants which consist of digits, they may or may not have decimal point(.).
- Numeric constant should have at least one digits.
- No comma or space is allowed within the numeric constant.
- Numeric constants can either be positive or negative but default sign is always positive.
- Decimal constants: e.g. 0,1,2,3,4,5,6,7,8,9. its base is 10.
- Octal constants: e.g. 0,1,2,3,4,5,6,7. its base is 8.
- Hex decimal : e.g. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f. its base is 16.
"blog"
Rules for defining numeric constants-
There are two type of numeric constants-
Integer constant : Integer constants are whole numbers which have no decimal point (.). There are three type of integer constants based on different number systems.
Some valid decimal integer constants are -
0
123
1234
908654
34456778
Some invalid decimal integer constants are-
2.3 illegal character(.).
4#33 illegal character #.
0444 first digits cannot be zero.only zero should be.
123 4 space not allow.
4,545 Comma is not allowed.
in Octal integer constants, first digits must be 0. e.g.
0
01
03
0453
in hexadecimal integer constants, first two characters should be 0x or 0X . eg.
0x
0x23
0x333
0xA4F1
By default the type of an integer constants is int.But if the value of integer constants exceeds the range of value represents by int type, the type is taken to be unsigned int or long int.
e.g. 45235 Integer constants of type int
45456566UL integer constants of type unsigned long int.
6655U type of unsigned of int.
I will explain about number System our next blog....
Real Constants: it is also called floating constants. Floating constants are numeric constants that contain decimal point. if decimal constant number have point(.) that called floating number. some valid floating point constants are-
0.5
4.4
3000.0
34.89
for expressing very large or very small real constants, scientific(exponent) form is used.in example, number is written in the mantissa and exponent form,which are separated 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 1800000 can be written as 1.8e6, here 1.8 is mantissa and 6 is exponent.
some other example: 2500000000 we write 2.5e9 or 2.5*1000000000
by default the type of a floating point constant is double.the symbol for recognizing is f or F (for float type) l or L( for Long double).
2.3e5 floating point constant of type double
2.4e-9L floating point of type long double.
3.5f floating point of type float..
2. Character constants: A character constant is a single character that is enclosed within single quotes.Some valid character constants are-
'3' 'A' '$' ' ' '#'
Some invalid character constants are-
'four' there should be only one character within quotes.
"A" double quote are not allowed
a single quote is missing.
'' no character between single quotes at least space should be.
Every character constant has a unique integer value associated with it. This integer is the numeric value of the character in the machine's character code. if the machine is using ASCII code then the character 'G' represents integer value 71 its means that if we write 71 it is a equal to 'G' and character 5 represent 53.
ASCII value is
A - Z ASCII value (65 -90)
a - z ASCII value (97 -122)
0 -9 ASCII value (48 - 57)
; ASCII value (59)
"342"
"3"
" "
"i"
Some valid decimal integer constants are -
0
123
1234
908654
34456778
Some invalid decimal integer constants are-
2.3 illegal character(.).
4#33 illegal character #.
0444 first digits cannot be zero.only zero should be.
123 4 space not allow.
4,545 Comma is not allowed.
in Octal integer constants, first digits must be 0. e.g.
0
01
03
0453
in hexadecimal integer constants, first two characters should be 0x or 0X . eg.
0x
0x23
0x333
0xA4F1
By default the type of an integer constants is int.But if the value of integer constants exceeds the range of value represents by int type, the type is taken to be unsigned int or long int.
e.g. 45235 Integer constants of type int
45456566UL integer constants of type unsigned long int.
6655U type of unsigned of int.
I will explain about number System our next blog....
Real Constants: it is also called floating constants. Floating constants are numeric constants that contain decimal point. if decimal constant number have point(.) that called floating number. some valid floating point constants are-
0.5
4.4
3000.0
34.89
for expressing very large or very small real constants, scientific(exponent) form is used.in example, number is written in the mantissa and exponent form,which are separated 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 1800000 can be written as 1.8e6, here 1.8 is mantissa and 6 is exponent.
some other example: 2500000000 we write 2.5e9 or 2.5*1000000000
by default the type of a floating point constant is double.the symbol for recognizing is f or F (for float type) l or L( for Long double).
2.3e5 floating point constant of type double
2.4e-9L floating point of type long double.
3.5f floating point of type float..
2. Character constants: A character constant is a single character that is enclosed within single quotes.Some valid character constants are-
'3' 'A' '$' ' ' '#'
Some invalid character constants are-
'four' there should be only one character within quotes.
"A" double quote are not allowed
a single quote is missing.
'' no character between single quotes at least space should be.
Every character constant has a unique integer value associated with it. This integer is the numeric value of the character in the machine's character code. if the machine is using ASCII code then the character 'G' represents integer value 71 its means that if we write 71 it is a equal to 'G' and character 5 represent 53.
ASCII value is
A - Z ASCII value (65 -90)
a - z ASCII value (97 -122)
0 -9 ASCII value (48 - 57)
; ASCII value (59)
"342"
"3"
" "
"i"
No comments:
Post a Comment