Type of C Contants- part 6

Type of C Contants- part 6

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:
    c
    #define PI 3.14159
    #define MAX_SIZE 100
  • These are replaced by their values during compilation.

6. Enumeration Constants

Created using enum for defining a set of named integer constants.

  • Example:
    c
    enum Color {RED, GREEN, BLUE};

Would you like a detailed explanation of any specific

CHAPTER -4 CONSTANTS ,VARIABLES AND DATA TYPES

Type of C Contants- part 6

Leave a Reply

Your email address will not be published. Required fields are marked *

error: