Hello World in D

Published on 25 March 2019 (Updated: 25 March 2019)

Hello World in D

In this article, we’re tackling Hello World in D.

How to Implement the Solution

At any rate, let’s get to the implementation of Hello World in D:

import std.stdio;
void main()
{
    writeln("Hello, World!");
}

At this point, you may be questioning whether or not D is even a new language. After all, this Hello World implementation looks a lot like C/C++.

Well, then it should come as no surprise the solution is pretty much the same. We have basically three main parts: the import statement, the main function, and the print function.

Just like C/C++, the first thing we do is import our standard output library. In this case, D references std.stdio as opposed to stdio.h in C.

Up next, we have our usual main function. At this point in the series, we’re pretty use to this syntax.

Finally, we have our typical print function. In this case, we call writeln and pass a string to it.1

How to Run the Solution

If we wanted to run our code snippet from above, we can leverage an online D compiler.

Alternatively, we can download our own D compiler from the official website. Then, we’ll want to get a copy of Hello World in D. After that, we can simply run the following:

rdmd hello-world.d

And, that’s it! The string “Hello, World!” should appear in the console.1


References

  1. J. Grifski, “Hello World in D,” The Renegade Coder, 8-May-2018. [Online]. Available: https://therenegadecoder.com/code/hello-world-in-d/. [Accessed: 25-Mar-2019].  2