- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the constant type qualifier in C language
Type qualifiers add special attributes to existing datatypes in C programming language.
There are three type qualifiers in C language and constant type qualifier is explained below −
Const
There are three types of constants, which are as follows −
Literal constants
Defined constants
Memory constants
Literal constants − These are the unnamed constants that are used to specify data.
For example,
a=b+7 //Here ‘7’ is literal constant.
Defined constants − These constants use the preprocessor command ‘define" with #
For example, #define PI 3.1415
Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.
The syntax is as follows −
const type identifier = value
For example,
const float pi = 3.1415
As, you can see that it simply gives a literal name.
Example
Following is the C program for constants type qualifier −
#include<stdio.h> #define PI 3.1415 main ( ){ const float cpi = 3.14 printf ("literal constant = %f",3.14); printf ("defined constant = %f", PI); printf ("memory constant = %f",cpi); }
Output
When the above program is executed, it produces the following result −
literal constant = 3.14 defined constant = 3.1415 memory constant = 3.14