Wednesday, December 21, 2011

Declaration of Variables


DECLARATION OF VARIABLES
In C, all variable must be declared before defining any executable statement in a program, but C++ allows declaration of the variables before and after executable statements. A declaration is a process of naming of the variables and their corresponding data types in C++.

 Usually, a declaration part is placed after the beginning statement and sometimes, some of the global variables can be defined or declared outside the program. (More derails of global variable are given in chapter 4, “Function and program structures”). A declaration consists of a data type followed by one or more variable names, ending with a semicolon.
    A variable is an object that may take on values of the specified type. The variable must be declared by specifying the data type and the identifier.

The general format of the variable declaration is
     data-type  identifiersl,  id2,. . . idn;
For example,
(1)
     char ch;
     where ch is a character data type.
(2)
      short int x,y;
      where x, y  are short integer data type and hole data size of 16 bits in length.
(3)
      long int x1 ;
      where xl is a long integer data type whose maximum size is 32 bits in length.
(4)
     unsigned int limit ;
     where limit is a variable and it has been declared as an unsigned integer data type.

1 comment: