D (The Programming Language)/d2/Types and Declaration

=Lesson 2: Types and Declarations= In this lesson, you will learn how to declare and use variables.

Concepts
In this lesson we see the declaration and assignment of variables.

Declaration Syntax
The syntax of declaring variables is You can also assign a value at the same time.

Declaring Multiple Variables in the Same Line
D allows you to declare multiple variables of the same type in the same line. If you write: i, j, and k are all declared as ints but only k is assigned 30. It is the same as:

Implicit Type Inference
If the declaration starts with, then the compiler will automatically infer the type of the declared variable. In fact, it doesn't have to be. Any storage class would work. Storage classes are built-in D constructs such as  or. This code declares an unchangeable variable a with a value of 3. The compiler figures out that the type is. You will learn much more about storage classes later.

More about writeln
is a very useful function for writing to stdout. One thing is special about writeln: it can take variables of any type. It can also take an unlimited amount of arguments. For example: Don't worry, there is nothing magical about. All the functions in the  family are implemented (in 100% valid D code) in stdio.d, which is in the Phobos standard library.

Tips

 * Syntax like this:   is not allowed.
 * Syntax like this:   is also not allowed.
 * is not a type. You cannot do this:    because there's no way the compiler can infer the type of i.    is merely a storage class, which tells the compiler to infer the type from the value that you assign it to in that same line.