- It refer to fixed values that the program may not change during its execution. These fixed values are also known as literals. Constants variable does not change value.
- C Constant is also like normal variable except their values can not be modified by the program once they are defined. They refer to fixed values.
- Constants are also known as literals.
- Constants variable is declare By “const” keyword in c language programming.
- In c language ,The constants are consist just like regular variables except that their values cannot be modified after their definition in c program.
Types of Constants in c
|1 . Integer constants|
|2 . Real or Floating point constants|
|3 . Octal & Hexadecimal constants|
|4 . Character constants|
|5 . String constants|
|6 . Backslash character constants|
- the first constants is Integer constants in constants type in c language . there are some rules of Integer constants in c. An integer constant must have at least one digit in c . integer constant must not have a decimal point. integer constant is No commas or blanks are allowed. The allowable range for integer constants is -32768 to 32767.
- there are int , unsigned int , long int , long long int datatype in integer constant.example of integer constant is 12,13,145 etc.
2.Real or Floating point constants
- there are some rules of Real or Floating point constants in c. A real constant must have at least one digit in c . Real or Floating point must have a decimal point. Real or Floating point constants No commas or blanks are allowed .
- there are float, double datatype in Real or Floating point. example of Real or Floating point is 10.10 , 123.121 etc.
3.Octal & Hexadecimal constants
- Octal & Hexadecimal constants and Integer constants are same datatype but Octal & Hexadecimal constants is starting with 0 .example of Octal & Hexadecimal constants is 012 , 09 etc.
- there are some rules of Character constants in c . Character constants are the constant which use single quotation around characters in c . example of character constants is ‘a’ , ‘b’ etc.
- there are some rules of String constants in c . A string literal is the representation of a string value within the source code of a c program . example of String constants is “this is the best” etc.
6.Backslash character constants
- in C language ,There are some characters which have special meaning . They should be preceeded by back slash symbol to make use of special function of them in c.
Example of constants variable
value of i : 123
value of j : 023
value of k : 3.14
value of l : A
value of m : ABC
value of n : \?