Constants

A constant is a also identifier whose value can't be hanged during the program execution. In C language we can declare constant using const or #define macro. Constants are also called as Literals. C Constants is divided into 2 categories.

  1. Numeric Constants
  2. Character Constants

Numeric Constants

Numeric constants are again divided into 2 types.

Integer Constants

Integer constants accepts only integer data type values. They won't accept point values. They can be either 'positive or negative' constants are again divided into two categories.

Infix int const

Infix integer constant indiates base of the value in which it has to be read.

Suffix int const

An integer literal(constant) can also have a suffix that is a combiantion of U and L, for unsigned and long, respectively.

Example: Real Constants / Floating Point Constant

Real constants also known as floating point constants. These are having fractional part either positive or negative. These real constant again for 2 forms.

  1. Decimal form: Decimal form it must contain decimal part.
    Example:3.423, -8.964, 8, 93
  2. Exponential form: Generally real or floating point constants are represented by using a format Mantissa
    Mantissa: The part appearing before e, Mantissa is a real number expressed in decimal notation.
    Exponent:Exponent is an integer number, it is positive or negative
  3. Letter 'e': Letter 'e' separation the mantissa and exponent that can be written in either lowercase (or) uppercase.
  4. Example:
    0.65 x 104 = 0.65e4
    12.5 x 10-2 = 12.5e-2
    1.5 x 105 = 1.5e+5
    3.18 x 103 = 3.18E3
    -1.2 x 10-1 = -1.2E-1
Character Constants

Character constants are divided into 3 types:

S.No Escape sequence Character represented
1. \a ALert(bell, alarm)
2. \b Backspace
3. \f Form feed
4. \n new line
5. \r Carriage return
6. \t Horizontal tab
7. \v Vertical tab
8. \' Single Quotation mark
9. \" Double quotation mark
10. \? Question mark
11. \\ Backslash
12. \0 Null character

Variables

In programming, a variable is a container(storage area) to hold data. To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location.

Example:int playerscore = 95;

Here, playerscore is a variable of int type. The int variable is assigned an integer value 95.

Rules for naming a variable:

How to declare a variable

The Variable declaration indicates that the operating system is going to reserve a piece of memory with that variable name.

Variable declaration

The syntax for variable declaration is as follows

type variable_name;   (single variable declaration)
or
type variable_name, variable_name, variable_name;     (Multiple variable declaration)
Syntax
int a,b,c;
int age;
char name;

Here a, b, c, age, name are variables. The int, char are the data types

Example program
#include<stdio.h>
int main() {
/* variable declaration */
int height, width;
height = 20;
width = 20;
printf("Value of height = %d \n value of width = %d", height, width);
return 0;
}

output

output is :

Value of height = 20
Value of width = 20