
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Const Qualifier in C
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'
- Related Articles
- Why do we use const qualifier in C++?
- Difference between const int*, const int * const, and int const * in C/C++?
- “volatile” qualifier in C
- Difference between const int*, const int * const, and int const * in C
- Difference between const char* p, char * const p, and const char * const p in C
- Const cast in C++
- Why do we use restrict qualifier in C++?
- Explain the constant type qualifier in C language
- Const member functions in C++
- Why do we use a volatile qualifier in C++?
- Declare a const array in C#
- enum vs. const vs. #define in C/C++
- What is the difference between const int*, const int * const, and int const *?
- What is the const Keyword in C++?
- Const vs Static vs Readonly in C#

Advertisements