Saturday, March 11, 2023

Variables and Constant



VARIABLE

  Definition

  1. It is a name of storage space which is used to store data.
  2. It's value is changeable.
  3. It always contains last value stored to it.
  4. It is always declared with data type.
    Variable declaration
    
      int rollno;
      float marks;
      char grade;
    Here rollno is a variable of type int, marks is a variable of type float and grade is a variable of type char.

     Variable Initialisation
     
       int rollno=354;
       float marks=74.4;
       char grade='R';
     Here 354 is the value of rollno, 74.4 is the value of marks and R is the value of grade. Character value is always written in single quotes.
  
     Rules to declare a variable
  1. The first letter of a variable should be alphabet or underscore( _ ).
  2. The first letter should not be digit.
  3. After first character it may be a combination of letter or digits.
  4. Blank spaces are not allowed in variable name.
  5. Variable name should not be a keyword.
 

CONSTANT

     Definition
  1. An element of program whose value can not be changed at the time of execution of program is called constant.
  2. It is also called literals.
  3. It may be int, float and character data type.
      Rules for constructing integer constant
  1. It must have atleast one digit.
  2. It must not have decimal point.
  3. It may no be positive or negative.
  4. The range of integer constant is between -32768 to +32767.
  5. No comma or blank space are allowed in integer constant.
      Rules for constructing floating point constant
  1. It must have atleast one digit.
  2. It must have a decimal point.
  3. It may be positive or negative.
  4. No comma or blank space are allowed in floating point constant.
      Rules for constructing character constant
  1. It is a single alphabet, digit or special symbol.
  2. The length of character constant is 1 character.
  3. Character constant is enclosed within single qoutes (example:- 'A').
       Use of constants in program
      There are two ways of using constants in the C program.
  1. Using const
  2. Using #define
      Example
        
       int rollno=354;
       float marks=74.4;
       char grade='R';
      Here  354 is integer constant, 74.4 is float constant and R is character constant.
      
        

BITWISE OPERATOR

  BITWISE OPERATOR In C, bitwise operators are used to perform operations at the bit level of operands. They manipulate individual bits with...