Constants in C

Constants in C

A constant is an identifier whose value remains fixed throughout the execution of the program. The constants cannot be modified in the program. For example: 1, 3.14512, „z‟, “hello" 

Different types of constants are: 

1) Integer Constant: An integer is a whole number without any fraction part. There are 3 types of integer constants:

i) Decimal constants (0 1 2 3 4 5 6 7 8 9)

For ex: 0, -9, 22

ii) Octal constants (0 1 2 3 4 5 6 7)

For ex: 021, 077, 033

iii) Hexadecimal constants (0 1 2 3 4 5 6 7 8 9 A B C D E F)

For ex: 0x7f, 0x2a, 0x521 

2) Floating Point Constant: The floating point constant is a real number. 

The floating point constants can be represented using 2 forms:

i) Fractional Form: A floating point number represented using fractional form has an integer part followed by a dot and a fractional part.

For ex: 0.5, -0.99

ii) Scientific Notation (Exponent Form): The floating point number represented using scientific notation has three parts namely: mantissa, E and exponent. 

For ex: 9.86E3 imply 9.86 x 103  

3) Character Constant: A symbol enclosed within a pair of single quotes(„) is called a character constant.

Each character is associated with a unique value called an ASCII (American Standard Code for Information Interchange) code. 

For ex: '9', 'a', '\n'

ASCII code of A = 65, a= 97, 0=48, etc

4) String Constant: A sequence of characters enclosed within a pair of double quotes(“) is called a string constant.

The string always ends with NULL (denoted by \0) character.

 For ex: "9", "a", "sri", "\n", “”

5) Escape Sequence Characters: An escape sequence character begins with a backslash and is followed by one character. 

 A backslash (\) along with some character give special meaning and purpose for that character. 

 The complete set of escape sequences are: 

\b Backspace

\f Form feed

\n Newline

\r Return

\t Horizontal tab

\v Vertical tab

\\ Backslash

\' Single quotation mark

\" Double quotation mark

\? Question mark

\0 Null character 

6) Enumeration constants: It is used to define named integer constants. It is set of named integer constants.

Syntax for defining enumeration constants enum identifier { enumeration-list}; // enum is a keyword

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz