Constants

                     Constants in C refer to fixed values that do not change during the execution of a program.

const:
                    It is a keyword and is used to declare constants.

Syntax:
                 const datatype identifier=value;
                                        (or)
                const datatype identifier-1=value,.........,identifier-n=value;
Eg:
                  const int a=100;
                  const int x=10, y=20, z=30;
Example:

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    const int n=100;
    clrscr();
    printf(" The given Constant Value  is            : %d", a);
    //n=100;
    printf("\nThe Change of Constant Value  is  : %d", a);
    getch();
}

Output:

The given Constant Value  is  : 100
The Change of Constant Value  is  : 100

                In the above program we given n=100, we will get an error can't modify a constant object.


No comments:

Post a Comment