C Programming language

C - Constant, Variables
Previous Home Next

Constant

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:

  1. Integer Constant
  2. Real Constant
  3. Character Constant

2. Secondary Constants:

  1. Array
  2. Pointer
  3. Structure
  4. Union
  5. Enum

Variables

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.

For Examples

A integer type of variable can hold integer constant.

Rules for constructing a variable name:-

  1. The first character in the variable name must be an alphabet or underscore.
  2. There should be no commas or blank spaces within variable name.
  3. There should not be any special symbol within a variable name except a underscore.
  4. Variable name should be 31 characters long.
  5. variable name should be meaningful so that user can understand.

Variable type

The Programming language C has two main variable types

  1. 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'.
  2. 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!

Data Type

DATA TYPEINITIALSER
int0
char'\'0
float0
pointernull

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.

Previous Home Next