The perfect place for easy learning...

C Programming Language

×

Topics List

Place your ad here

C Variables

Variables in a c programming language are the named memory locations where the user can store different values of the same datatype during the program execution. That means a variable is a name given to a memory location in which we can store different values of the same data type. In other words, a variable can be defined as a storage container to hold values of the same datatype during the program execution. The formal definition of a data type is as follows...

Variable is a name given to a memory location where we can store different values of the same datatype during the program execution.

Every variable in c programming language must be declared in the declaration section before it is used. Every variable must have a datatype that determines the range and type of values be stored and the size of the memory to be allocated.

A variable name may contain letters, digits and underscore symbol. The following are the rules to specify a variable name...

  1. Variable name should not start with a digit.
  2. Keywords should not be used as variable names.
  3. A variable name should not contain any special symbols except underscore(_).
  4. A variable name can be of any length but compiler considers only the first 31 characters of the variable name.

Declaration of Variable

Declaration of a variable tells the compiler to allocate the required amount of memory with the specified variable name and allows only specified datatype values into that memory location. In C programming language, the declaration can be performed either before the function as global variables or inside any block or function. But it must be at the beginning of block or function.

        Declaration Syntax:

datatype variableName;

        Example

                int number;

The above declaration tells to the compiler that allocates 2 bytes of memory with the name number and allows only integer values into that memory location.


Place your ad here
Place your ad here