# C language: What is Constants in C Programming language?

In C language the item whose values cannot be changed during the execution of the program. numbers, real numbers, characters, and strings of characters are constants.

These fixed values are also known as literals. C language constants can be classified as follows.

## Numeric Constants in C language

### Integer Constant

An Integer constant is formed with the sequence of digits. There are types of integer constants that form different number systems. An integer literal can be a decimal, octal, or hexadecimal constant.

A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal. An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order.

 Deciaml 0 to 9 Octal number 0 to 7 Hexadecimal number 0 to 9, A, B, C, D, E, F

Here are some examples of integer literals:

 Deciaml 10, 153, -365, 7689, 19 etc. Octal number 037, 9, 052, 0541, etc. Hexadecimal number 0x4, 0x8F, 0XBCF etc.

Following are other examples of various types of Integer literals:

 85 /*decimal*/ 0213 /*Octal*/ 0x4b /*Hexadecimal*/ 30 /*int*/ 30u /*unsigned int*/ 30l /*long*/ 30ul /*unsigned long*/

### Rules for defining an Integer constant in c language:

1. It must have at least one digit.
2. Decimal points are not allowed.
3. Integer constant can be either positive or negative.
4. If it is negative, the sign must be preceded, for positive the sign is not necessary.
5. No commas or blank spaces are allowed.
6. The allowable range for integer constants is -32, 768 to +32, 767.

### Real constants or Floating-Point

A real constant is made up of a sequence of numeric digits with the presence of a decimal point. Real constants serve a good purpose to represent quantities that vary continuously such as distance, heights, temperatures, etc.,

Here are some examples of floating-point literals:

 distance = 126.0; height = 5.6; speed = 3e11;

### Rules for defining real Constant in c language:

1. The real constant must have one digit.
2. Real constant must have decimal point.
3. It can be either positive or negative.
4. If it is negative, the sign is a must or if it is positive, the sign is not necessary.
5. No commas or blank spaces are allowed

## Character constants

### Single character constants

Character literals are enclosed in pair of single quotes, e.g., ‘B’, and can be stored in a simple variable of char type. Like char = ‘B‘ ; .

A character literal can be a plain character (e.g.,’ X’), an escape sequence (e.g.,”), or a universal character (e.g., ‘ˀ’).

There are certain characters in C language when they’re preceded by a backslash they will have special meaning and they’re used to represent like newline or tab. Here, you have a list of some similar escape sequence codes.

Escape SequenceMeaning
\\\character
\’‘character
\”“character
\?? character
\bbackspace
\fformfeed
\nNew line
\rcarriage return
\tHorizontal tab
\vvertical tab

When the above code is compiled and executed, it produces the following result:

`Hello     world`

## String constants in C language

String literals or constants are enclosed in double- quotations . A string constant is a sequence of characters enclosed in double quotes, the characters may be letters, numbers, special characters, blank spaces, etc. At the end of the string ‘\0’ is automatically placed.

Example:

“hi”, “Amber”,”39.22″,”29″

The output of this Program is

`I Learn C`

### Declaring a variable as constant

When the value of some of the variables may remain constant during the execution of the program. In such a situation, this can be done by using the keyword const.

syntax: const datatype variable = constant

description: const  is the keyword to declare constant

variable   is the name of the variable

datatype  is the type of the data

constant  is the value

Example: const int dob = 3977

The following example program explains it in detail:

Output:

`value of area : 50`

### Declaring a variable as volatile

The volatile variables are those variables that are changed at any time by other external programs or the same program. ANSI standard defines qualifier as volatile.

Syntax: volatile datatype variable = constant

Description: volatile is the keyword to declare volatile.

the variable is the name of the variable.

datatype is the type of data.

constant is the constant

Example: volatile int year = 2022;

The value of a variable declared as volatile can be modified by its own program as well.

If the value of a variable in the current program is to be maintained constant and desired not to be changed by any other external operation, then the declaration of the variable will be as follows.

volatile const int year = 2017 ;

[note: The compiler can not modify the value of the variable which is assigned by using the keyword const.]

## Delimeter in C Programming language

These are the symbols, which have some syntactic meaning and have got significance. These will not specify any operation. C language delimiters list is given below.

 Symbol Name Meaning # Hash Pre-processor directive , Comma variable delimeters to a separate list of variables : Colon Label delimeters ; Semicolon Statement delimeters () Parenthesis Used in expressions or in function {} Curly braces Used for blocking ‘C’ structure [ ] Square braces Used along with arrays