D is a compiled systems language with C-like syntax, garbage collection by default, and fast compile times. Its standard library is Phobos, and its runtime is druntime.
D · Lesson 1 · On the house
Program structure
A D source file, main, imports from Phobos, writeln, and compiling with dmd, ldc2, or gdc. Lesson 1 is free — on the house.
Lessons · D · Lesson 1 of 10 · On the house
Program structure
A D source file, main, imports from Phobos, writeln, and compiling with dmd, ldc2, or gdc.

Every program starts at void main() (or int main(string[] args) to read arguments and return an exit code).
import std.stdio; brings in writeln (prints its arguments then a newline), write (no newline), and writefln (printf-style formatting).
Three compilers share one frontend: dmd (the reference compiler, fastest builds), ldc2 (LLVM backend, well-optimized code), and gdc (GCC backend). dmd -run app.d compiles and runs in one step, and rdmd app.d does the same with caching.
writeln takes any number of arguments of any type and prints them with no separator: writeln("x = ", 3) prints x = 3.
Comments are // to end of line, /* ... */, and /+ ... +/, which nests, so you can comment out a block that already contains comments.
hello
import std.stdio;
void main(string[] args)
{
writeln("Hello, D");
write("no newline, ");
writeln("then one");
writeln("args: ", args.length, ", answer = ", 6 * 7);
writefln("%s is %d years old", "D", 2026 - 2001);
/+ nested /* comments */ are fine +/
}
Quiz
Which import provides writeln?
Quiz
What separator does writeln put between its arguments?
Quiz
Which comment form nests?
Quiz
What does args.length print when the program runs with no arguments?
Check
Match the still for: Program structure.
Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.