Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Smita Kapse

We use the const qualifier to declare a variable as constant. That means that we cannot change the value once the variable has been initialized. Using const has a very big benefit. For example, if you have a constant value of the value of PI, you wouldn't like any part of the program to modify that value. So you should declare that as a const.

Objects declared with const-qualified types may be placed in read-only memory by the compiler, and if the address of a const object is never taken in a program, it may not be stored at all. For example,

Example

#include<stdio.h>
int main() {
   const int x = 10;
   x = 12;
   return 0;
}

Output

[Error] assignment of read-only variable 'x'

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.