What is Constants in C Programming language in Detail ?

What is Constants in C language ?
What is Constants in C language ?



 Upon completing this article,you will be able to:

  • What is Constant in C language ?
  • Different types of Constant in C language.
  • What is Numeric Constant in C language ?
  • What is Character Constant in C language ?
  • What is Integer Constants in C language ?
  • What is Real Constant in C language ?
  • What is Single Character Constant in C language ?
  • What is String Constant in C language ?

Constants in C:-

Constants in C language refer to fixed values that do not change during the execution of a program.C support different types of constants as illustrated in fig


Numeric Constant in C:-

There are two types of Numeric Constant are define in C language.

  1. Integer Constant.
  2. Real Constant.

1.Integer Constant in C:- 

An integer constant in C language is nothing but it is a sequence of digits.There are three types of integers constant namely,decimal integer,octal integer and hexadecimal integer.

  • Decimal integer constant consist of a set of digits,0 through 9,preceded by an optional - to +.Valid example of decimal integer are:123, -321,0,+76 etc.
  • An octal integer constant consists of any combination of digits from the set 0 through 7,with a leading 0.Some example of octal number are: 034,0,0455,0551 etc.
  • A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer constant.They may also include alphabet A through F, The letter A through F represent the numbers 10 through 15.Following are the example of valid hex integers are: 0X2,0x9F,OXBCD etc.
Note:- The largest integer value that can be stored is machine dependent.it is 32767 on 16-bit machine and 2,147,483,647 on 32-bit machine.it is also possible to store larger integer value constant on these machine by appending qualifiers such unsigned integer, long interger,unsigned long integer.Example: 57789U(unsigned integer),987612347UL(unsigned long integer),9876543L(long integer).

2.Real Constant in C:-

Integer number are inadequate to represent quantities that vary continuously,such as distance,heights,temperature,prices and so on.These quantities are represented by numbers containing fractional part like 17.548.Such number are called real or real constant.

  • These constant are shown in decimal notation,having a whole number followed by a decimal point and the fractional part.It is  possible to omit digits before the decimal point or digit after the decimal point.i.e: 215.,.87,-.71 are all valid number.
  • A real number may also be represent in exponential(scientific notation).For example the value 215.65 may be written as 2.156e2 in exponential notation,e2 multiply by 100. 

Character Constant in C:-

There are two type of character constant  are define in C language.
  1. Single Character Constant.
  2. String Constant.

1.Single Character Constant in C:-

A single character constant (or simply character constant) contains a single character enclosed within a pair of single quote mark.Example of character constant is follow as: '5','X' etc.

Note:- The character constant '5' is not as the the number 5.The last constant is blank space Character constants have integer values know as ASCII value.

ASCII Value:- Each character constant(uppercase,lowercase of alphabet) in C language represents an integer value and these specific value of every character are know their ASCII value.
  • The ASCII value of  uppercase letter(A to Z) is from 65 to 90.
  • The ASCII value of  lowercase letter(a to z) is from 97 to 122.
  • The ASCII value of  0 to 9 is from 48 to 57.
  • The ASCII value of  special character(&,%) is from 33 to 47.     
2.String Constant:-

A string constant is a sequence of characters enclosed in double quotes.The character may letters number,special character and blank space.Example are:
"Hello","2003","WELL DONE" etc.


Backslash Character Constants in C:-

C support some special type of constant which is Backslash Character Constant,This constant is used in output functions.For example,the symbol '\n' stand for newline character.

Conclusion:-

In this article we have got learnt about constant in C language in details,but if you have got any doubt are remaining regarding to this current topic then you can comment below I will try to resolve your doubt as soon as possible.

Post a Comment (0)
Previous Post Next Post