Constant in C

Constant is a fixed value which can be store or assign to variable. In other language constant called literals.

Constant variable example:

	
    int		 a		 	= 		       10
     ↓		 ↓      	  	↓                      ↓
    datatype	variable	assignement_operator	fixed value
    

In above example a variable have fixed value which can't be change.

There is different type of constant

In C there is two type of constant.

Numeric Constant

Integer Constant Floating Constant / Real Constant
1. Decimal Constant float (10.456789)
2. Octal Constant double (600.123456789)
3. Hexadecimal Constant

Example of integer constant:

	
    int a = 10;
    int a = 011;
    int a = 0x11;
    

Example of floating constant:

	
    float a = 10;	//10.0
    float a = 010;	//8.0 Ocatal Representation
    float a = 012.34	//12.34 Ocatal Representation
    
    float a = 0x10;	//16.0 // we can't represent floating value in hexadecimal form.
    

Non-numeric Constant

Non-numeric Constant
Character Constant String Constant

Example of character constant:

	
    char ch = 'a';	//single alphabet constant
    char ch = '4';	//
    char ch = ' ';	//white space constant
    char ch = '@';	//special symbole constant
    char ch = 97;	//ascii code of english alphabet- it will result as (a)
    char ch = 'abc'	//invalid character constant
    

Example of string constant:

string or string Constant a group of characters enclose with double quotes (" ") symbol called string.

	
    char ch = "campuslife";
    

Post Your Comment