Whatever we calculated, it stores in memory. Computer memory has millions of cells also known as memory Locations. If the memory location has a value it does not change called constant.
Types Of Constants
There are two types of constants
1. Primary Constants:
- Integer Constant
- Real Constant
- Character Constant
2. Secondary Constants:
The Name which are given to the memory locations called Variables. These memory location contains constants (Integer, Real and Character). Types of variables depend on types of variables that it can handle.
Particular type of variable can hold only the same type of constants.
A integer type of variable can hold integer constant.
Rules for constructing a variable name:-
- The first character in the variable name must be an alphabet or underscore.
- There should be no commas or blank spaces within variable name.
- There should not be any special symbol within a variable name except a underscore.
- Variable name should be 31 characters long.
- variable name should be meaningful so that user can understand.
The Programming language C has two main variable types
- Local Variables
- Local variables scope is confined within the block or function where it is defined. Local variables must always be defined at the top of a block.
- When a local variable is defined - it is not initialized by the system, you must initialize it yourself.
- When execution of the block starts the variable is available, and when the block ends the variable 'dies'.
- Global Variables
- Global variable is defined at the top of the program file and it can be visible and modified by any function that may reference it.
- Global variables are initialized automatically by the system when you define them!
If same variable name is being used for global and local variable then local variable takes preference in its scope. But it is not a good practice to use global variables and local variables with the same name.