The Constants in C are those identifiers which value are never change.There are four basic types of constants in C:
1. integer constants
2. floating-point constants
3. character constants
4. string constants
3 different number systems are used:
1. integer constants
2. floating-point constants
3. character constants
4. string constants
3 different number systems are used:
decimal, octal and hexadecimal.
Some valid decimal integer constants:
0 1 743 5280 32767 9999
Some invalid decimal integer constants:
12,245 36.0 10 20 30 123-45-678 0900
Some valid octal integer constants:
0 01 0743 077777
Some invalid octal integer constants:
743 05280 0777.777
Some valid hexadecimal integer constants:
0X1 0X7FFF 0xabcd
Some invalid hexadecimal integer constants:
0X12.34 0BE38 0x.4bff 0XDEFG
Unsigned and long integer constants
Unsigned and long integer constants
50000U(decimal unsigned)
123456789L(decimal long)
123456789UL(decimal unsigned long)
0123456L(octal long)
0777777U(octal unsigned)
0X50000U(hexadecimal unsigned)
0XFFFFFUL(hexadecimal unsigned long)
Floating-Point Constants
A floating-point number is a base-10 number that contains either a decimal point or an
A floating-point number is a base-10 number that contains either a decimal point or an
exponent(or both). Some valid floating-point constants:
0. 1. 0.2 827.602
5000. 0.000743 12.3 315.0066
2E-8 0.006e-3 1.6667E+8 .12121212e12
Some illegal floating-point constants:
1
1,000.0
2E+10.2
2E 10
Character Constants
A character constant is a single character enclosed in apostrophes(i.e., single quotation
marks)
Example: ‘A’ ‘x’ ‘3’ ‘?’ ‘ ’
65 120 51 63 32
String Constants
A string constant consists of any number of consecutive characters(including none),
enclosed in double quotation marks.
Examples:
“green” “Oxford University, UK”
“270-32-3456” “$19.95” “ ”
“Line 1\nLine 2\nLine3” “\tTo be continued”
0 comments:
Post a Comment