Javatpoint Logo
Javatpoint Logo

Constants in C

A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc.

There are different types of constants in C programming.

List of Constants in C

Decimal Constant10, 20, 450 etc.
Real or Floating-point Constant10.3, 20.2, 450.6 etc.
Octal Constant021, 033, 046 etc.
Hexadecimal Constant0x2a, 0x7b, 0xaa etc.
Character Constant'a', 'b', 'x' etc.
String Constant"c", "c program", "c in javatpoint" etc.

2 ways to define constant in C

There are two ways to define constant in C programming.

  1. const keyword
  2. #define preprocessor

1) C const keyword

The const keyword is used to define constant in C programming.

Now, the value of PI variable can't be changed.


The value of PI is: 3.140000

If you try to change the the value of PI, it will render compile time error.


Compile Time Error: Cannot modify a const object

2) C #define preprocessor

The #define preprocessor is also used to define constant. We will learn about #define preprocessor directive later.

Visit here for: #define preprocessor directive.

Next TopicLiterals in C

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA