Constant in C programming

Constant – Constant in C language is that item whose value remains same during the execution of the program from the beginning till the end of a program.

Constant may be a numeric constant or a unknown numeric constant.. Numeric constants are of two types. These are-

  • Integer constant  Integer constant is a data element that has no fractional part or exponent. For ex – 3, 400, 23589, 32356 etc.
  • Real of Floating point constant – This type of constant represents decimal point numbers. These numbers includes integer part, fractional part and an exponent. For ex- 4.034, 3574.12835, 24.65, 0.3 etc.
Variable constant C programming

Constant Variable

From the above Image you can see that abc is a variable and 30 is constant. Variable’s value can be changed one or more times during the execution of the program but constant  will remain fixed throughout the program.Constant value is always stored in the variable.

Character constants are of  two types-

  • Single character constant – Single character constant is announced in c programming language in single quotes and has a single character. For ex – ‘a’, ‘f’ , ‘e’ ‘s’ etc.
  • String type constant – String type constant is announced in double quotes. For ex – “hello”, “fun”, “cprogram” etc. You can take the example from the above image also. Likewise string type or any other constants can also be declared.

Backslash Character Constants

C language supports some special backslash character constants that are used in output functions. For example ‘n’ stands for newline character. Note that each one of them represents a backslash and a character after it. These combinations are also known as escape sequences

Backslash Character constants
Constant Meaning
\a audible alert (bell)
\b back space
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\’ single quote
\” double quote
\? question mark
\\ backslash
\0 null

yashan has written 69 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>