Home > Article > Backend Development > What are the different types of constants in C language?
Constant is a value that cannot be changed during program execution;
In C language, a number or a character or a string is called a constant. It can be of any data type. Constants are also called literals.
There are two types of constants -
Main constants - Integers, floating point numbers and characters are called main constants.
Auxiliary constants - Arrays, structures, pointers, enumerations, etc. are called auxiliary constants.
const datatype variable;
Real-time demonstration
#include<stdio.h> int main(){ const int height=20; const int base=40; float area; area=0.5 * height*base; printf("The area of triangle :%f", area); return 0; }
The area of triangle :400.000000
Real-time Demo
include<stdio.h> void main(){ int a; int *p; a=10; p=&a; printf("a=%d</p><p>",a);//10// printf("p=%d</p><p>",p);//address value of p// *p=12; printf("a=%d</p><p>",a);//12// printf("p=%d</p><p>",p);//address value of p// }
a=10 p=6422036 a=12 p=6422036
The above is the detailed content of What are the different types of constants in C language?. For more information, please follow other related articles on the PHP Chinese website!