Constant and Variable in C Programming

Constant and Variable in C Programming

Constant and Variable in C Programming

Constant
  1. Constant is an entity that does not change during program execution. Example when we write number=10 than 10 is constant in all program and never change value.
  2. There are mainly two types constants:
    1. Primary constants
      • Integer constant
      • Real Constant
      • character Constant
    2. Secondary Constants
      • Array
      • Structure
      • Pointer
      • Union

Rules for construction Integer Constant
  • At least one digit must have an integer constant
  • It can be positive or negative. The general range of integer constant is -32768 to +32767.(NOTE : Normally range depend on compiler.)
  • No commas or blank spaces are allowed within integer constant.
  • Integer constant must not having decimal point.
  • Example of integer constant are as 364,-66,+786,-1
Rules for constructing Floating point or Real constant
  • At least one digit must have an real constant.
  • Real constant must have decimal point.
  • It may be positive or negative.
  • No commas or blank spaces are allowed within real constant.
  • Example of real point constant : +23.0, 786.786, -0.786, 0.0
 Rules for constructing Character constant
  • Any single entity(like as single alphabet, single digit or single symbol) are enclosed within single inverted commas, are called character constant.
  • Example of Character constant : 'a', 'A', '*', '4' etc..


Variable
  1. Variable is an entity that change during program execution. Example when we write r = 45 i.e. x can hold different value at different times so r is a variable.
  2. A variable may be integer,character,float,double etc..
 Rules for constructing Variable Names : 
  • A variable name must be start with alphabet or underscore.
  • A variable name is any combination of 1 to 31 alphabets,digits or underscores.
  • No commas,special symbol(rather than underscore [ _ ] ) or blanks are allowed within a variable name
  • Example of valid variable names : ram, _ram, d_x, _voids, echo_,  



KeywordsC, C++, programming, C++ tutorials, C++ programming, C programming, source code, programming quiz
Previous
Next Post »