Ada Programming/Variables

From Wikibooks, open books for an open world
Jump to navigation Jump to search
This computer programming article is available in pseudocode and Ada.

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Variables are references that stand in for a value that is contained at a certain memory address.

Variables are said to have a value and may have a data type. If a variable has a type, then only values of this type may be assigned to it. Variables do not always have a type.

A value can have many values of many different types: integers (7), ratios (1/2), (approximations of) reals (10.234), complex numbers (4+2i), characters ('a'), strings ("hello"), and much more.

Different languages use different names for their types and may not include any of the above.

Assignment statements[edit source]

An assignment statement is used to set a variable to a new value.


Assignment statements are written as name := value.

  X := 10;

The example set the variable X to the integer value of 10. The assignment statement overwrites the contents of the variable and the previous value is lost.

In some languages, before a variable can be used, it will have to be declared, where the declaration specifies the type.


Ada is the same. The declaration is as follows:

declare
  X : Integer := 10;
begin
  Do_Something (X);
end;

Uses[edit source]

Variables store everything in your program. The purpose of any useful program is to modify variables.

See also[edit | edit source]

Ada Reference Manual[edit | edit source]