
- 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
What are different types of constants in C language?
Constant is a value that cannot be changed during program execution; it is fixed.
In C language, a number or character or string of characters is called a constant. And it can be any data type. Constants are also called as literals.
There are two types of constants −
Primary constants − Integer, float, and character are called as Primary constants.
Secondary constants − Array, structures, pointers, Enum, etc., called as secondary constants.
Syntax
const datatype variable;
Example for Primary constants
#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; }
Output
The area of triangle :400.000000
Example for secondary constants
include<stdio.h> void main(){ int a; int *p; a=10; p=&a; printf("a=%d
",a);//10// printf("p=%d
",p);//address value of p// *p=12; printf("a=%d
",a);//12// printf("p=%d
",p);//address value of p// }
Output
a=10 p=6422036 a=12 p=6422036
- Related Articles
- What are different types of constants in C++?
- What are different types of data in C language?
- What are the different types of pointers in C language?
- What are the different types of keywords in C language?
- What are Backslash character constants in C language?
- What are the constants with an example in C language?
- What are types of expressions evaluated in C Language?
- What are primary data types in C language?
- What are constants in C++?
- What are the different searching techniques in C language?
- What are different format specifiers used in C language?
- What are the different data types of arrays in C#?
- What are different types of access modifiers available in C#?
- What are the different types of functions in C Programming?
- What are Enumerated Constants in C++?

Advertisements