C Constants

In C programming language, constants are fixed values that do not change during the program execution. Constants can be of different data types, and they are used to define values that are not expected to change. There are two types of constants in C programming language:

  1. Numeric Constants: Numeric constants are used to represent numbers. They can be of different types, such as integers, floating-point numbers, or characters.

Examples:

int num = 10;            // integer constant
float pi = 3.14;         // floating-point constant
char ch = 'A';           // character constant
  1. Symbolic Constants: Symbolic constants are used to define values that are not expected to change during the program execution. They are defined using the #define directive and are given a name.

Example:

#define MAX_SIZE 100     // symbolic constant

In the above example, MAX_SIZE is a symbolic constant, and its value is set to 100 using the #define directive.

Constants are used in C programming language to make the code more readable and maintainable. By using constants instead of hard-coded values, you can easily change the values of the constants without modifying the code. This makes the code more flexible and easier to maintain.

Comments

Leave a Reply

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

94802