Constants in C are fixed values that do not change throughout the program. The constant can be viewed as a read only memory variable. Constants can be declared using the keyword const.
Syntax:
const variable_name=value;
Types of Constants:
Constants are broadly classified into numeric constants and character constants.
Numeric Constants:
i. Integer Constants
ii. Real Constants
Character Contants:
i. Character constants
ii. String Constants
Integer Constant:
Integer constants are whole number which has no decimal point. In ‘C’ there can be three types of integer constants:
· Decimal Integer: 0-------9(base 10)
· Octal Integer: 0-------7(base 8)
· Hexadecimal Integer: 0----9, A------F(base 16)
Example: 15, -265, 0, 99818, +25, 045, 0X6
Real constant:
Real constant is also called floating point constant. These have fractional parts to represent quantities like average, fees, height, area etc. which cannot be represented by integer number precisely.
A real constant can be represented in 2 forms.
1. Decimal form E.g. 15.5
2. Exponent form E.g. 1275E-2, -14E-2
Character Constant:
A character constant is a single character surrounded by a pair of single quotes. A character value occupies 1 byte of memory.
Example: 'X', '5', ';'
The character constant '5' is not the same as the integer 5. Each character constant has an ASCII (American Standard Code for Information Interchange) value associated with it. For example, the following statement will print 65 and A respectively:
printf(“%d”, ‘A’);
printf(“%c”, ‘65’);
String Constant:
A string constant is a group of characters surrounded by double quotes. These characters may be letters, numbers or any special characters.
Example: "2015", "welcome"
0 Comments
if you have any doubts plz let me know...