Sunday, December 22, 2019

Constants & Variables in C

⇒ Constant:-

    Constant is a value that can't be change during the execution of program. They are classified into following type

  1. Numeric Constant:-

(a) Integer Constant:-

    -These are the sequence of numbers from 0 to 9 without decimal points or fractional part of any other symbols. It required minimum two bytes and maximum four bytes.
    -Integer constant could be either positive or negative or may be zero e.g. -10,20,+35,-15 etc
    -They can also be represented in octal or hexadecimal number 
e.g. 
  • Octal no.- 027,035,079 etc.
  •  Hexadecimal no.- 0X9,0Xab,0XA etc.

(b) Real Constant:-

    -Real constant are also known as floating point constant. Integer constant are not fit to represent many quantities e.g. Length,Height,Distance etc.

    2. Character Constant:-

(a) Single character constant:-

    -A character constant is a single character constant.
    -It can also be represented with single digits ore single special symbol or white space enclosed within a pair of single quote (' _ ') mark e.g. 'a','8','_','D' etc.

(b) String Constant:-

    -String constant are a sequence of characters enclosed within double quote("_") mark.
    -The string may be a combination of all kind of symbol e.g."Hello","India","999","a".

 Variable:-

    -Variable is a value that can be change during the execution of program. A variable is a data name use for storing a data value. In other words a variable can be assign different value  at different times during the program execution. 
    -A variable name may be declared based on the meaning  of the operations. Variable names made up of letters and digits. Variable are the basic objects manipulated in a program.
    -Variable declaration gives an introduction of variable to compiler and its properties like scope, range of values and memory required for storage.
    -A variable is used to store values. It have memory location and can store single value at a time e.g. Height,Average,Sum etc.

Rules for Declaring Variable:-

  • A variable must be begin with a character or an underscore(_) without space. The underscore is treated as one type of character.
  • It is advised that the variable name should not start with underscore because library routines mostly use such variables name.
  • The length of the variable varies from compiler to compiler. Generally most of the compiler support 8 character excluding extension .
  • The ANSI standard recognizes the maximum length of a variable up to 31 characters.
  • The variable should not be a C-keyword.
  • The variable name may be a combination of UPPERCASE and lowercase character e.g. suM,sum etc.
  • The variable name should not start with a digits.
  • Blanks & Commas are note permitted with in a variable name.

No comments:

Post a Comment