# C – Constant and Types of Constant

Constants, also called literals, are the actual representation of fixed values used in the program. All the numeric representations without fractional (such as 0, 20, 81563) are considered as the integer constant and all the numeric representation that has fractional part or exponential part (such as 5.6, 3.3, 3.55e55) are known as floating point constants.

The alphabetic, numeric or other symbolic characters are characters constant.Â Â Character constants are represented by enclosing character inside single quote (such as ‘a’, ‘%’, ‘+’).

The collection of multiple character constants is called string constants which are enclosed in double-quotes (i.e “Ram”, “Sita”, etc).Â Â Different constants used in C are as follows;Â

**Integer Constant****Decimal Constant****Hexadecimal Constant****Octal Constant**

**Floating Point Constant****Character Constant****String Constant**

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<conio.h> //above header files //below symbolic constant

#define PI 3.1412

#define TRUE 1

#define FALSE 0 Â

## Integer Constant

The integer constants are the fixed numeric representation that does not have a fractional part.

Integer constants may be positive or negative numbers without a fractional part. There are three types of integer literals.

### I) Decimal Literals:

Decimal literals are the integer numbers represented with base 10 number system. No point or comma is allowed in the decimal literal. Some examples of decimal literals are 124,Â +54, -54, 84884 etc.

### II) Hexadecimal Literals

Hexadecimal numbers are the integer numbers that have base sixteen. These numbers use digits from 0 to 9 and alphabets from A to F (or a to f).

Hexadecimal numbers are written using 0x before actual digits. Some examples of hexadecimal literals are 0xBe, 0x3, 0xCA3, 0xBBA etc.Â

### III) Octal Literals

They are the integer numbers with base eight. Octal numbers use digital from 0 to 7. Octal numbers are written using 0 before the octal digits. Some examples of octal integers are 043, 01743, 0203457 etc.Â

## Floating Point Constant

The fixed numeric representation that has fractional part or exponential part is called floating point constant or real constant.

The floating-point literals can be represented in fractional form or exponential form.

No commas are allowed in a floating-point number. In fractional form, the number has integer part and fractional part separated by a point and in exponential form, the number has an integer part, a fractional part, and exponential part.

If the fractional part of the integer part has the value 0, then we may omit it, but we must use the point to indicate that it is a floating-point constant.

The integer part and fractional part are separated by a decimal point and the exponential part is separated by letter ‘e’. No space is allowed in any numbers. Some floating-point literals are 4. 71, 43, 4., 4.5e-23 etc.

## Character Constant

A character represented within single quotes denotes a character constant. Following are some examples.

‘a’, ‘z’, ‘x’ etc. Actually, character literals are internally represented as integer numbers. Most of the computer use ASCII character set in which each character is assigned 7-bit code but character set may be implementation-defined.

Internally each character is stored as an 8-bit integer. There are some special characters written with (backslash) as the escape character.

For example n for a new line, t for horizontal tab, b as backspace, r carriage return, f form fee, an alert, \ backslash, ‘ single quote, Â ” double quote.

## String Constant

A string literal is a character sequence enclosed withing double quote. If double quote (“) or single quote (‘) are to be part of the string they should be preceded Â by backslash. Following are the example of the string literal.Â

"Republic New Nepal" To mean just republic new Nepal.Â

"Ravi' S wife" to mean Ravi's wife.

"He said "Health is Wealth"" to mean He said "health is Wealth".Â

A string literal contains one more character, that is null character ” at the end that it actually appears to have. Another special escape character can be used within string as;Â

printf("stringt for test an");

String can be broken into two lines by white space character as

printf("........................................"

"...................................................");

The two-line string will be concatenated by the compiler to make a single string. Even if we write two string in a single line as “Donald” Duck” it will mean “DonaldDuck” to the compiler.