WHAT IS CONSTANT?

Variables having fixed values that don’t change and cannot be changed throughout the execution of the program once initialized are called Constants.

Constants in C programming  can be declared in two ways,

      • Using const keyword 
      • #define preprocessor directive                                                   


USING CONST KEYWORD

                Syntax :-  const  data_type  constant_name  =  constant_value;


                Example :- const float PI = 3.1412;

#define PREPROCESSOR DIRECTIVE

#difine function come before the program main block.

                Syntax :- #define constant_name constant_value

                Example :- #define PI 3.1412


TYPES OF CONSTANTS IN C

            1. Primary Constants

      • integer
      • float
      • character
            2. Secondary Constants
      • arrays
      • pointers
      • structures
      • unions
      • enums


INTEGER CONSTANT

Integer constants represent whole numbers. They can be in various bases like decimal, octal, or hexadecimal.

                       const int decimalConstant = 42; //Here decimal value 42 is assigned as decimalConstant

                       const int octalConstant = 052; // Octal equivalent of 42

                       const int hexConstant = 0x2A; // Hexadecimal equivalent of 42


FLOATING POINT CONSTANT

Floating-point constants represent numbers with a decimal point and can include the use of scientific notation.

                        const float pi = 3.1415926;

                        const double e = 2.71828;


CHARACTER CONSTANT

Character constants represent single characters enclosed in single quotes.

                        const char grade = 'A';

                        const char newline = '\n';


STRING CONSTANT

String constants represent sequences of characters enclosed in double quotes.

                        const char greeting[] = "Hello, World!";

                        const char name[] = "Keethu";