Constants in C

Constants in C are value which cannot be changed in entire program.

For example : 69 or "C programming" , 'A' , these all are constants and cannot be changed.


All these constants are of four types :

1. Integer constants

2. Floating point constants

3. Character constants

4. String constants


Integer Constants

These are integers i.e numbers which are  positive , negative or zero without decimal point.

example : 12 , 1500, -1000 , -2 ,30000

Although this is very simple there are some rules which we should follow like a lot of time specially in print we use symbols like , or - to separate numbers but in C it cannot be used.

12,000 is invalid.
12000 is valid.

similarly date like format cannot be used like 2008-07-06 is not a valid integer constant

Also we cannot use point or decimal for Integer constants 
36.0 is invalid
36 is valid

Floating point constants 

Floating points are number with point or decimal numbers , positive , negative or zero.
example : 15.5 , 7.6,  -2.6, 234.54, -798.5666

All above rules of symbols like  ,    -  apply to floating point as well except that dot ( . )  is allowed as it is floating point numbers .

Character constants

A character constant is single character enclosed in single quote . 

Example 'A' or 'P' , 'Y' or 'N'
A lot of time we use single character for the tasks like yes, Y or No ,N  . Also male M or female F.
In those cases character constants are useful.

String Constants

String constants are any number of consecutive characters enclosed in double quote.

Example : "john" , " Hi , I am John Doe" , " C programming"

well string is an array of Characters and have \0 or NULL character inserted at the end , it cannot be seen when displayed but can be accessed through array method. 

Example : 'A' and "A" is not same .
'A' is just a single character.
"A" is string and is array  of two characters 'A','\0'

Contact Form

Name

Email *

Message *