What is constant? Write down briefly about different type of constant?


Constants are of fixed values that do not change during the execution of a program. There are various types of constants. The types are illustrated in the following figure.


Integer constants: 

An integer constant refers to a sequence of digits. There are three types of integer constants, namely, decimal integer, octal integer and hexadecimal integer.

Decimal integer consists of a set of digits from 0 to 9, preceded by an optional + or – sign. 

Examples,      123     -321    0          64932

Octal integer consists of a set of digits from 0 to 7, with a leading 0. 

Examples, 037     0      0437         0551

Hexadecimal integers are a sequence of digits preceded by 0x or 0X. They may also includes letters from A to F or from a to f. The letters represents the numbers from 10 to 15.Examples,            0X2     0x9F   0Xbcd    0x

Real constants:

Real constants are used to represent quantities that are very continuously, such as distances, temperature etc. These quantities are represented by numbers containing fractional parts. Examples,      0.00832          -0.75               33.337

Single character constants:

A single character constants contains a single character enclosed within a pair of single quote marks. Example, ‘5’         ‘X’       ‘;’

String constants:

A string constant contains a string of characters enclosed within a pair of double quote marks. Examples,    “Hello !”         “1987”            “?....!”

Backslash character constants:

C supports some special backslash character constants that are used in output functions. For example

                  Constants                                                    Meaning
                        ‘\a’                                                       audible alert (bell)
                        ‘\n’                                                      new line

                        ‘\?’                                                       question mark

Author: Tanmay Chakrabarty

Tanmay Chakrabarty is a former CSE student, currently working as a Senior Software Engineer with 5+ years of experience in the field of Web Application development in PHP+MySQL platform with strong skills in Javascript, JQuery, JQuery UI and CSS. He tries to write notes every week but fails due to heavy loads of duty.

Recommended Recommends


Contact Us