Type of C Contants- part 6
Type of C Contants- part 6
Contents
- 1 Types of Constants in C (Part 6)
- 2 1. Integer Constants
- 3 2. Floating-Point (Real) Constants
- 4 3. Character Constants
- 5 4. String Constants
- 6 5. Symbolic Constants
- 7 6. Enumeration Constants
- 8 CHAPTER -4 CONSTANTS ,VARIABLES AND DATA TYPES
- 9 Type of C Contants- part 6
- 10 Unit-I Chapter 2 C Tokens: Character set, Identifiers, …
Types of Constants in C (Part 6)
In the C programming language, constants are fixed values that do not change during program execution. Constants can be classified into different types based on their data type and usage.
1. Integer Constants
Integer constants are whole numbers (without decimal points). They can be:
- Decimal (Base 10):
10, 25, -100
- Octal (Base 8, starts with 0):
012 (equivalent to 10 in decimal)
- Hexadecimal (Base 16, starts with 0x):
0xA (equivalent to 10 in decimal)
2. Floating-Point (Real) Constants
Floating-point constants represent decimal numbers or numbers in exponential form.
- Example:
3.14, -0.001, 1.2E3 (equivalent to 1.2 × 10³ = 1200)
3. Character Constants
A single character enclosed in single quotes (‘ ‘).
- Example:
'A'
,'5'
,'@'
- Each character constant has an ASCII value (e.g.,
'A'
= 65).
4. String Constants
A sequence of characters enclosed in double quotes (” “).
- Example:
"Hello"
,"C Programming"
- Stored as an array of characters with an implicit
\0
(null terminator).
5. Symbolic Constants
Defined using the #define
preprocessor directive.
- Example:
- These are replaced by their values during compilation.
6. Enumeration Constants
Created using enum
for defining a set of named integer constants.
- Example:
Would you like a detailed explanation of any specific