Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
D is a compiled systems programming language created by Walter Bright at Digital Mars and first released in 2001, conceived as a redesign of C++ that keeps the performance while shedding much of the complexity. It is multi-paradigm — you can write imperative, object-oriented, functional, and heavily template-based code — and it compiles straight to fast native machine code. Its standard library is called Phobos, and modules such as `std.stdio` and `std.algorithm` cover everyday tasks. D also offers optional garbage collection alongside manual memory control, so you can pick the model that fits the job. On XCODX your source is compiled and run directly, giving you Phobos and the core language to experiment with in the browser.
import std.stdio;
import std.string : strip;
void main()
{
write("Enter your name: ");
string name = readln().strip();
writeln("Hello, ", name, "!");
foreach (i; 1 .. 6)
writeln(i, " squared is ", i * i);
}
D works well when you want C++-level speed with a friendlier, more productive language — high-performance backends, numerical and systems code, and command-line tools are natural fits, and its ranges and templates make data-processing pipelines expressive. Choose it when you value both compile-time metaprogramming and the option of garbage collection. It reads familiarly to C, C++, and Java programmers, which eases the learning curve. It is less suited to settings that forbid any runtime or to teams needing the very largest package ecosystem, and here the Dub package manager is unavailable, so only Phobos is importable.
No. The sandbox exposes only the Phobos standard library — there is no Dub, no network access, and no persistent filesystem, so external packages cannot be downloaded. Your imports have to resolve to `std.*` or the core modules that ship with the compiler.
Use `readln()` from `std.stdio`, which returns the line including its trailing newline, so it is common to call `.strip()` (from `std.string`) to trim it. In the live terminal the program pauses at `readln` until you type and press Enter, or you can pipe input through the Stdin Box; Ctrl+D signals end of input. For formatted reads there is also `readf`.
Yes, D includes an optional garbage collector by default, but you are not forced to lean on it — you can use manual allocation, `@nogc` code, or scoped destruction when you need deterministic control. This dual model is one reason D spans both application and systems programming.
No, though it borrows their curly-brace style and much of their performance. D adds modules, optional garbage collection, built-in slices and arrays, cleaner templates, and compile-time function execution, while dropping the C preprocessor. A good deal of C code can be translated to D with modest changes.
The runtime badge shows the exact version; the sandbox typically runs a recent D 2.x compiler. You cannot switch compilers or pin a different release here.
Each run happens in a fresh, isolated environment with no persistent disk and no network, so files you create do not survive between runs and remote resources are unreachable. Use stdin and stdout for input and output within a single execution.
main.ddreadln()import std.stdio;
void main() {
writeln("Hello from D!");
writeln("Welcome to XCODX Online Compiler!");
string message = "D is awesome!";
writeln(message);
}