A variable is a symbolic representation denoting a value or expression.


Variables can be contrasted with constants, which are known and unchanging.

A variable is usually named by an identifier, but it can be anonymous and can be associated with another variable.

C++

In C++ the format of a variable or constant declaration statement is as follows:

[const][ modifiers] type identifier[ = expression][ , identifier[ = expression][ , ...]] ;

where

const is the const keyword and indicates that a constant is being declared. If the const modifier is omitted, a variable is declared.
modifiers modify the range and precision of the variable or constant and whether it can contain negative numbers.
type is the type specifier of the variable or constant.
identifier is the identifier by which it will be possible to refer to the variable or constant.
= is the assignment operator = and indicates that the value of an expression is to be assigned.
expression is the expression that is evaluated.
, delimits the variables or constants being identified.
; closes the declaration and delimits it from the next statement.

Arrays

When working with closely related data of the same type and scope, it is often convenient to store them together in a data structure instead of in individual variables. The most common data structure is the array. Arrays are fixed-length structures for storing multiple values of the same type.

In Java, an array is declared in the same way any variable is declared. The type is the type of the elements contained in the array. The [] notation is used to indicate that the variable is an array. For example:

int   single   ;
int[] multiple ;

In this example single is a single integer variable and multiple is an array of integer variables.


example GCC C++
Borland C++ Compiler
Java
home Home Page