Types of Constants in C: Integer, Float, Character, String and Enum
C has 5 main types of constants: integer, floating-point, character, string and enumeration constants. See rules and examples for each type.
The 5 types of constants in C
1. Integer constants
int a = 100; /* decimal */
int b = 0x1F; /* hexadecimal (31) */
int c = 025; /* octal (21) */
long d = 500000L; /* long suffix */
unsigned e = 40U; /* unsigned suffix */
- No decimal point, no commas:
1,000is invalid — write1000. - Prefix
0xmeans hexadecimal, prefix0means octal — a common trap:025is 21, not 25.
2. Floating-point constants
float pi = 3.14159f; /* f suffix = float */
double rate = 8.75; /* default type is double */
double big = 1.5e6; /* scientific: 1500000.0 */
A number with a decimal point or exponent (e) is a floating constant. Without a suffix it is double; add f for float or L for long double.
3. Character constants
char grade = 'A'; /* single character in single quotes */
char nl = '\n'; /* escape sequence: newline */
char tab = '\t'; /* escape sequence: tab */
char zero = '\0'; /* null character */
"A" (double quotes) is a string constant, not a character constant — a very common exam question.4. String constants
char name[] = "CodingEasily"; /* double quotes */
printf("Hello World\n"); /* string literal in printf */
A string constant is a sequence of characters in double quotes. The compiler automatically appends a hidden '\0' (null terminator) at the end, so "Hi" actually takes 3 bytes.
5. Enumeration constants
enum Day { MON, TUE, WED, THU, FRI, SAT, SUN };
/* MON=0, TUE=1, ... SUN=6 automatically */
enum Level { LOW = 1, MID = 5, HIGH = 10 }; /* custom values */
Enum constants are named integer constants. They are true compile-time constants, so they work in case labels and array sizes.
Summary table
| Type | Example | Key rule |
|---|---|---|
| Integer | 100, 0x1F, 025 | No decimal point or commas |
| Floating-point | 3.14f, 1.5e6 | Decimal point or exponent; default double |
| Character | 'A', '\n' | Single quotes, one character |
| String | "Hello" | Double quotes, hidden '\0' at end |
| Enumeration | enum {LOW, HIGH}; | Named integers, compile-time constant |
C में constants के 5 प्रकार
1. Integer constants
int a = 100; /* decimal */
int b = 0x1F; /* hexadecimal (31) */
int c = 025; /* octal (21) */
long d = 500000L; /* long suffix */
unsigned e = 40U; /* unsigned suffix */
- न decimal point, न commas:
1,000invalid है —1000लिखें. - Prefix
0x= hexadecimal, prefix0= octal — common trap:025का मतलब 21 है, 25 नहीं.
2. Floating-point constants
float pi = 3.14159f; /* f suffix = float */
double rate = 8.75; /* default type double है */
double big = 1.5e6; /* scientific: 1500000.0 */
Decimal point या exponent (e) वाला number floating constant है. Suffix के बिना यह double होता है; float के लिए f और long double के लिए L लगाएं.
3. Character constants
char grade = 'A'; /* single quotes में single character */
char nl = '\n'; /* escape sequence: newline */
char tab = '\t'; /* escape sequence: tab */
char zero = '\0'; /* null character */
"A" (double quotes) string constant है, character constant नहीं — बहुत common exam question.4. String constants
char name[] = "CodingEasily"; /* double quotes */
printf("Hello World\n"); /* printf में string literal */
String constant double quotes में characters की sequence है. Compiler अंत में automatically एक hidden '\0' (null terminator) जोड़ देता है, इसलिए "Hi" असल में 3 bytes लेता है.
5. Enumeration constants
enum Day { MON, TUE, WED, THU, FRI, SAT, SUN };
/* MON=0, TUE=1, ... SUN=6 automatically */
enum Level { LOW = 1, MID = 5, HIGH = 10 }; /* custom values */
Enum constants named integer constants हैं. ये true compile-time constants हैं, इसलिए case labels और array sizes में काम करते हैं.
Summary table
| Type | Example | Key rule |
|---|---|---|
| Integer | 100, 0x1F, 025 | न decimal point, न commas |
| Floating-point | 3.14f, 1.5e6 | Decimal point या exponent; default double |
| Character | 'A', '\n' | Single quotes, एक character |
| String | "Hello" | Double quotes, अंत में hidden '\0' |
| Enumeration | enum {LOW, HIGH}; | Named integers, compile-time constant |
Frequently Asked Questions
How many types of constants are there in C?
C has 5 main types of constants: integer, floating-point, character, string and enumeration constants.
What is the difference between 'A' and "A" in C?
'A' in single quotes is a character constant (1 byte value), while "A" in double quotes is a string constant of 2 bytes: the letter A plus a hidden null terminator.
Is 025 equal to 25 in C?
No. A leading zero makes it an octal constant, so 025 equals 21 in decimal, not 25.