C Programming Tutorial
Computer Tutorial

C Variables and Types of Variables



Variables

a variable is a named location in memory that is used to hold a value that can be modified by the program. All variables must be declared before they can be used. These location can contain integer, real or character constants.
The general form of a declaration is :
Variable type   variable_name;
Ex- int a, b, c;
char ch, si;

Rules for Constructing Variable Names

» A variable name is any combination of 1 to 31 alphabets, digits or underscores.
» The first character in the variable name must be an alphabet or underscore.
» No commas or blanks are allowed within a variable name. No special symbol other than an underscore (as in gross_sal) can be used in a variable name.

Types of Variable

1. Local Variables
2. Global Variables

Local Variables

Variables that are declared inside a function are called local variables. In some C literature, these variables are referred to as automatic variables. Local variables can be used only by statements that are inside the block in which the variables are declared.

Global Variables

Global variables are known throughout the program and may be used by any piece of code. Also, they will hold their value throughout the program's execution. You create global variables by declaring them outside of any function. Any expression may access them, regardless of what block of code that expression is in.

\* C Program to show the Local and Global Variables. *\
# include < stdio.h >
int   count ; /* count is Global Variable */
int   main( )
{

int   num ; /* num is local Variable */
count = 100 ;
num = 50 ;
.
.
.

}