C Programming Constant

Constant

Constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a
floating constant, a character constant, or a string literal. There are enumeration constants as well.

Define Constant

Constant in C means the content whose value does not change at the time of
execution of a program.

Example:

#include >stdio.h <

int main() {

   printf("Hello\tWorld\n\n");

   return 0;
}

Constant Digram




Types Of Constant

1. Integer constants

2. Floating-point constants

3. Character constants

4. Escape Sequences

5. String constants

6. Enumeration constants

1.Integer constants :

An integer constant is a numeric constant (associated with number) without any fractional or
exponential part. There are three types of integer constants in C programming:
decimal constant(base 10)
octal constant(base 8)
hexadecimal constant(base 16)

Decimal constants: 0, -9, 22 etc
Octal constants: 021, 077, 033 etc
Hexadecimal constants: 0x7f, 0x2a, 0x521 etc

2.Floating-point constants :

A floating point constant is a numeric constant that has either a fractional form or an
exponential part. There are three types of integer constants in C programming:
exponent form. For example:

-2.0
0.0000234
-0.22E-5

3.Character constants :

A character constant is a constant which uses single quotation around characters. For
example: 'a', 'l', 'm', 'F':

4.Escape Sequences :

Sometimes, it is necessary to use characters which cannot be typed or has special meaning in
C programming. For example: newline(enter), tab, question mark etc. In order to use these :
characters, escape sequence is used.:

-2.0
0.0000234
-0.22E-5

5. String constants :

String constants are the constants which are enclosed in a pair of double-quote marks. For

"good"                  //string constant
""                     //null string constant
"      "               //string constant of six white space
"x"                    //string constant having single character.
"Earth is round\n"         //prints string with newline

6. Enumeration constants :

Keyword enum is used to define enumeration types. For example:

enum color {yellow, green, black, white};



                   <<  PREVIEW   >>




                   <<   NEXT    >>

Comments