C Variable

A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at Different times during execution. A variable name can be the programmer in a meaningful way so as to reflect its function or nature in the program.

The rules for writing the variable names are given below.

  1. Variable names consist of letters, digits and underscore.
  2. Variable names must begin with an alphabet or underscore.
  3. Variable names could have length up to 31 characters.
  4. Variable names are case sensitive i.e., "SUM" and "sum" are not equivalent.
  5. Keywords should not be used as, a variable names.
  6. Blank spaces, commas and special symbols are not allowed within variable names.

Variable declaration:

A variable stores data value of different types and to avoid the confusion to compiler, variables are declared with a data type. It can store only the data values of the type associated with it.
Syntax: data type variable_name=data_value;

Example:
int x=10;
Thus,"x" is a variable that can store only integer values.

CONSTANTS:

Constants in C refer to the values that do not change during the execution of the program.Depending on the types of the data they represent,constants are classified in to two classes.

1. Numeric constants: Numeric constants can be classified as,
a) Integer constants and
b) Real constants.

a) Integer constants: An integer constant refers to a sequence of digits.These are further classified into three types depending on the number systems they belong to they are

  1. Decimal integer constant
  2. Octal internal constants
  3. Hexa decimal constant

DECIMAL INTEGER CONSTANT: - A decimal integer constant is characterized by the following properties.

  1. It is a sequence of one (or) more digit ({0....9}, the symbols of decimal numbers system).
  2. It may have an optional + or - sign. In the absence of sign, the constant is assumed to be positive.
  3. It should not have a period as a part of it.
  4. Commas and blank spaces are not permitted.

Valid decimal integer constant:-345 ,-987
Invalid decimal integer constant;-3.45 decimal point is not permitted.
3, 34 commas are not permitted.

OCTAL INTEGER CONSTANT:-An octal integer characterized by the following properties.

  1. It is a sequence of one or more digit ([0....7], symbols octal number system).
  2. Same as above.
  3. It should start with digit 0.
  4. It should not have a period as a part of it.
  5. Commas and blanks are not permitted.

Valid: - 0345
invalid:-03.34 decimal point is not permissible

HEXA DECIMAL INTEGER CONSTANT: -

A hexa decimal integer constant is characterized by the following properties.

  1. It is a sequence of once or more symbols ([0...9][a...z],the symbols of hexa decimal number system.
  2. Same as above.
  3. It should start with symbols 0* or 0*.
  4. Same as above.

Valid:-0*345
invalid:-0*3.45 decimal is not permissible

b) Real constants:

Integer numbers are inadequate to represent quantities that vary continuously, such as Distances, heights, etc. These quantities are represented by numbers containing fractional parts Like 17.548. Such numbers are called real constants. The representation of a floating-point .Real constants are often called floating point constant the real constants could be written in two forms, fractional form &exponential form.

RULES WHILE CONSTRUCTING REAL CONSTANTS EXPRESSED IN FRACTIONAL FORM:-

(a) A real constant must have at least one digit.
(b) It must have decimal point.
(c) It could be either +ve or -ve.
(d) Default sign is +ve
(e) No commas (or) blank are allowed with in a real constant


Character constants:

A single character contains a single character constant enclosed within a pair of a single quote marks.
Example: "a","5" etc
Character constants have integer values that are determined by the computer"s particular character set .most computers make use of the ASCII character set, in which each individual character is numerically encoded.
Example: "A" =65
Maximum of one character is taken within a character constant

String constants:

A string constant contains sequence of characters (i.e., alphabets, digits, special symbols and blank spaces) enclosed in double quotes.
Example:
"Hello!"
"1987"
"?...!"

Backslash character constants:

C supports some special backslash character constants that are used in output functions. Each character constant has its own purpose and contains two characters. These character combinations is called "Escape sequence". Some of them are shown in the table given below. Constant
"\a", "\b", "\f", "\n", "\r", "\t", "\v", "\"", "\?", "||", "\0"