Discuss various types of constants in C.

What is constants? Explain the types of constants with suitable example.

Constants are also like normal variables. But, only difference is, their values cannot be modified by the program once they are defined.

Constants refer to fixed values. They are also called as literals

Constants may be belonging to any of the data type.

Syntax:

const data_type variable_name; (or) const data_type *variable_name;

TYPES OF C CONSTANT:

  1. Integer constants
  2. Real or Floating point constants
  3. Octal & Hexadecimal constants
  4. Character constants
  5. String constants
  6. Backslash character constants

Constant type  data type (Example)

 
 Integer constants
int (53, 762, -478 etc )
unsigned int (5000u, 1000U etc)
long int, long long int
(483,647 2,147,483,680)
Real or Floating point constants
float (10.456789)
doule (600.123456789)
Octal constant
int (Example: 013 /*starts with 0 */)
Hexadecimal constant
int (Example: 0x90 /*starts with 0x*/)
character constants
char (Example: ‘A’, ‘B’, ‘C’)
string constants
char (Example: “ABCD”, “Hai”)