DIZNR INTERNATIONAL

Type of C Contants- part 6

Type of C Contants- part 6

https://www.gyanodhan.com/video/7A2.%20Computer%20Science/Let%20Us%20C%20Programming/184.%20Let%20Us%20C%20by%20Yashavant%20P.%20Kanetkar%20-%20Type%20of%20C%20Contants-%20part%206.mp4

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:

2. Floating-Point (Real) Constants

Floating-point constants represent decimal numbers or numbers in exponential form.

3. Character Constants

A single character enclosed in single quotes (‘ ‘).

4. String Constants

A sequence of characters enclosed in double quotes (” “).

5. Symbolic Constants

Defined using the #define preprocessor directive.

6. Enumeration Constants

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

Would you like a detailed explanation of any specific

CHAPTER -4 CONSTANTS ,VARIABLES AND DATA TYPES

Type of C Contants- part 6

Unit-I Chapter 2 C Tokens: Character set, Identifiers, …

Here’s a structured and easy-to-understand explanation of:

C Programming – Types of Constants (Part 6)

Suitable for BCA, B.Tech, Diploma, or beginner programmers.


What are Constants in C?

A constant is a fixed value that does not change during the execution of a program.

Constants are used in programs to make them more readable and maintainable.


Types of Constants in C

C supports several types of constants, broadly categorized as:

1⃣ Integer Constants

  • Whole numbers without decimal.
  • Example: 10, -5, 0, 2000

Types:

  • Decimal (Base 10): 25
  • Octal (Base 8): starts with 0, e.g. 037
  • Hexadecimal (Base 16): starts with 0x, e.g. 0x1F

2⃣ Floating-point Constants

  • Numbers with decimal point or in exponential (scientific) notation.
  • Example: 3.14, -0.001, 2.5e3

3⃣ Character Constants

  • A single character enclosed in single quotes ' '.
  • Example: 'A', 'z', '5'

Each character constant has an ASCII value internally.

char ch = 'A'; // ASCII value = 65

4⃣ String Constants

  • A sequence of characters enclosed in double quotes " ".
  • Example: "Hello", "1234", "C Programming"
char str[] = "Hello";

5⃣ Enumeration Constants (enum)

  • Used to define named integer constants.
  • Improves readability of code.
enum Days { MON, TUE, WED, THU, FRI };

Here, MON is 0, TUE is 1, etc.


6⃣ Defined Constants (#define)

  • Use the preprocessor directive #define to create constants.
#define PI 3.14
#define MAX 100

Once defined, PI will always be replaced with 3.14.


Summary Table

Constant Type Example
Integer 100, -23
Floating-point 3.14, 2.0e3
Character 'A', '7'
String "Hello"
Enumeration enum Colors {RED, BLUE}
Defined (#define) #define PI 3.14

Tips

  • Constants make code easier to read and maintain.
  • Use const keyword to declare variables as constants:
const int age = 18; // age cannot be changed

Would you like:

  • Practice questions on constants?
  • A PDF revision sheet?
  • A quiz to test your understanding?

Let me know, and I’ll provide it!

Type of C Contants- part 6

Programming in C with Numerical Methods Unit I Chapter II …