Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.
Version 4 (modified by csauls, 18 years ago)
Goodbye, "Source," and hello multi-decleration explanation.

Variables

Part of TutorialFundamentals

Description

Creating "slots" to store data.

Example

void main() {
  int myInt,
      myint,
      MYINT;
}

More Information

Declare three separate integer variable called myInt, myint, and MYINT. Like many things in D, variable declarations are a lot like C, C++, and Java. In D, all variables have to be declared before they are used. Note that (again, like C, etc) multiple variables can be declared at once, seperated by commas.

Some Facts About Identifiers

  1. Identifiers must begin with a letter, or an underscore. Use of leading underscores is, however, generally discouraged, as this pattern is used for reserved names, such as _arguments.
  2. Subsequent characters can be numbers or underscores as well as additional letters.
  3. Identifiers can be as long as you want.
  4. Note that variable identifiers in D are case-sensitive. (In the above example, "myInt", "myint", and "MYINT" are separate identifiers.)