C Constants

Constants:

        Constants in C refer to fixed values that do not change during the execution of  the program.   
     Constants are classified as shown below.



(i). Integer Constants :

An integer constant refers to a sequence of digits without any decimal point. There are three types of     integer constants namely decimal integer, octal integer and hexadecimal integer.
 Decimal/Integer constant: It consists of set of digits 0 through 9, preceded by an optional – or + sign. No special symbol and spaces is allowed between digits. Examples : 123, -321, +78

Octal Integer constant : It consists of set of digits 0 through 7, preceded with 0. No special symbol and spaces is allowed between digits. Examples : 037, 0435

Hexadecimal Integer constant : It consists of set of digits 0 through 9, and A to F or a to f, preceded with 0x or 0X.  No special symbol and spaces is allowed between digits.  Examples:  0x37, 0x435A


(ii). Real Constants:

Numbers that contain fractional parts and whose value does not change. Such numbers are called real (floating point) constants. It is possible to represent real constant number by omitting digits before decimal point or digits after the decimal point. Examples:   0.0083 435.56 .345 215.

Real number may also be expressed in exponential (Scientific) notation as shown below:
Example: 215.15 can be written as 2.1515e2. (Mantissa, Base, Exponent).

(iii). Single Character Constants:

Any character enclosed in single quotes is considered as single character constant.
                   Examples:    ‘5’,  ‘x’
The ‘C’ Programming Language  supports backslash character constants that can be used in output functions along with the string. These constants have predefined meaning and they are treated as single character constant.

(iv). String Constant / Strings:


Any sequence of characters enclosed in double quotes is considered as string constant.
             Examples:     “welcome” , “134”.
         Note:  The ‘a’ is character constant, where as “a” is string constant.

(v). Boolean constants: 

 The  0 ( false) and 1 (true) is called as Boolean constant.

Variables:

• It is an identity for a memory cell, which stores input values, computational values and output values.
• It is named as variable because, its value changes continuously throughout program execution.
• The variable declaration specifies to compiler about what type of value is stored in the variable and also specifies about list of variables used in the program.
Variable Representation:
A variable is a location in memory that is identified by a name and address and can store value of a particular type as shown below. 
Example:  int  sum=21;


                 
Rules for declaring Variable Name :

1. An variable name must consist of only alphabetic character , digits, and underscore.
2. First character must be alphabetic character or  under score and should not be a digit.
3. Second character onwards  can be alphabetic character or digit or under score.
4. Variable name can be up to  31/63 characters depending on the system.(  first 8 characters are significant)
5. It cannot be same as  key word / reserved word.
6. May not have a white space or any other special symbol except under score.
7. C – language is Case-sensitive. So that, the variable name should be defined specifically to uppercase or  
     lower case letters.


Examples for User defines Identifiers :
          Valid identifiers                           In Valid identifiers
          Rollnumber, Name                          4you, Do  today,  #welcome
          Subject1, marks                            auto, int      
          College_name

Declaration of  a Variable:

1.  Single variable of specified data type can be declared as
  data_type_name   var_name;     Example: int  tot_marks;
2. Multiple variables of same data type can be declared as
     data_type_name  var_name1, var_name2,….;    Example:  int a, b, c; 

Initialization of Variables:
The variables can be initialized by using assignment operator as shown below.
1. The variable declaration and inialization can be specified separately as shown        below 
               Syntax :
                              data_type_name var_name;
                              var_name= Initial_value;
                              Example:  int sum;
                                 sum=0;
2. The variable declaration and inialization can be specified combinely  as shown below 
            Syntax :            
                          data_type_name var_name = Initial_value;   
                           Example:      int sum=0;