DEV Community

Cover image for Types of Constants in C
Mukesh Kumar
Mukesh Kumar

Posted on

Types of Constants in C

πŸŽ™οΈ Introduction

Hello everyone!

In the previous lesson, we understood what a constant is β€” a value that cannot change during program execution.

Now the next question is:

πŸ‘‰ Are all constants the same?
πŸ‘‰ Or are there different types of constants in C language...Read More

πŸ”Ή Step 1: What Are Types of Constants?

In C programming, constants are mainly divided into the following types:

  1. Integer Constants
  2. Floating-Point Constants
  3. Character Constants
  4. String Constants
  5. Enumeration Constants

Each type represents a different kind of fixed...Read More

πŸ”Ή Step 2: Integer Constants

Integer constants are whole numbers without any decimal point.

Examples:

10

0

-25

1000 These constants represent integer values.

They can be:

Positive (25)

Negative (-50)

Zero (0)

Integer constants are commonly used for...Read More

πŸ”Ή Step 3: Floating-Point Constants

Floating-point constants are numbers that contain a decimal point.

Examples:

3.14

0.5

-2.75

100.00

These constants represent real numbers.

They are used when precision or fractional values are...Read More

πŸ”Ή Step 4: Character Constants

Character constants represent a single character enclosed in single quotation marks.

Examples:

'A'

'b'

'5'

'#'

Important points:

Only one character is allowed...Read More

πŸ”Ή Step 5: String Constants

String constants are a group of characters enclosed in double quotation marks.

Examples:

"Hello"

"C Programming"

"2026"

"Nepal"

Important points:

Must be enclosed in double quotes.

Can contain letters, numbers, and symbols...Read More

πŸ”Ή Step 6: Enumeration Constants

Enumeration constants are defined using the enum keyword.

They represent a set of named integer constants.

For example:
Days of the week:

MON

TUE

WED

Internally, these are stored as integers starting...Read More

πŸ”Ή Step 7: Symbolic Constants

Apart from the above types, C also allows symbolic constants using:

const keyword

define preprocessor directive

For example:

PI

MAX

LIMIT

These are named constants that represent fixed values...Read More

πŸ“Œ Summary of Types of Constants

Let’s quickly revise:

Integer Constants β†’ Whole numbers

Floating-Point Constants β†’ Decimal numbers

Character Constants β†’ Single character in single quotes...Read More

Top comments (0)