Constant in c programming language

  •  What is a Constant?

A constant is a value that cannot be modified once it is defined.

Example:

C

10

3.14

'A'

"Hello"

🔹 Types of Constants in C

C constants are mainly divided into:

  1. Integer Constants
  2. Floating (Real) Constants
  3. Character Constants
  4. String Constants
  5. Enumeration Constants
  6. Symbolic Constants

1️⃣ Integer Constants

These are whole numbers (without decimal point).

Types of Integer Constants

(a) Decimal Integer

Base 10 numbers

Digits: 0–9

Example:

C

10

-25

500

(b) Octal Integer

Base 8 numbers

Starts with 0

Digits: 0–7

Example:

C

075

012

(c) Hexadecimal Integer

Base 16 numbers

Starts with 0x or 0X

Digits: 0–9 and A–F

Example:

C

0x1A

0XFF

2️⃣ Floating (Real) Constants

These contain decimal points or exponential form.

Types:

(a) Fractional Form

C

3.14

-0.98

10.0

(b) Exponential Form

C

1.5e3 // 1.5 × 10³

2E-2 // 2 × 10⁻²

3️⃣ Character Constants

A single character enclosed in single quotes ' '.

Example:

C

'A'

'5'

'#'

Escape Sequences (Special Characters)

Escape          Meaning

\n                     New line

\t                      Tab

\b                     Backspace

\0                      Null character

Example:

C

'\n'

'\t'

4️⃣ String Constants

A group of characters enclosed in double quotes " ".

Example:

C

"Hello"

"India"

"123"

👉 String always ends with a null character \0.

5️⃣ Enumeration Constants

Defined using enum keyword.

Example:

C

enum day {MON, TUE, WED};

Here:


MON = 0

TUE = 1

WED = 2

6️⃣ Symbolic Constants

These are names given to constants using:

(a) #define

C

#define PI 3.14

#define MAX 100

(b) const keyword

C

const int x = 10;

Comments

Popular posts from this blog

History of c programming language

Evolution of programming languages

How to Create a Bloger account