Constants and Literals in C
A constant is a value or variable that can not be changed by the program once they are defined.
TYPES OF CONSTANT
- Integer constants
- Real or Floating point constants
- Octal & Hexadecimal constants
- Character constants
- String constants
- Backslash character constants
Data type (Example)
||int (53, 762, -478 etc )
unsigned int (5000u, 1000U etc)
long int, long long int
|Real or Floating point constants
||int (Example: 013 /*starts with 0 */)
||int (Example: 0x90 /*starts with 0x*/)
char (Example: ‘A’, ‘B’, ‘C’)
char (Example: “ABCD”, “Hai”)
Rules for Constants
1) Integer Constants
- In integer constant must have at least one digit.
- It do not consist of decimal point.
- It can either be positive or negative.
- No commas or blanks are allowed within an integer constant.
- An integer range is -32768 to 32767.
2) Real Constants
- A real constant must have at least one digit
- It contants decimal point.
- It could be either positive or negative
- No commas or blanks are allowed within a real constant.
3) Character And String Constants
- A character constant constant single alphabet, a single digit or a single special symbol enclosed within single quotes.
- The maximum length of a character constant is 1 character.
- String constants are enclosed within double quotes.
4) Backslash Character Constants
- In Backslash Character Constants contants some characters which have special meaning in C language.
- List are below.
||Alert or bell
||Octal constant (N is an octal constant)
||Hexadecimal constant (N – hex.dcml cnst)
value of height : 100
value of number : 3.140000
value of letter : A
value of letter_sequence : ABC
value of backslash_char : ?
Literals in C
Literals is a constant (fixed) values that cant not be change the tme of execution program.
Types of Literals
There are 4 types of literals that is.
- Integer literal
- Float literal
- Character literal
- String literal