Values in D Programming Language
D has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
import std.stdio;
void main()
{
// Strings, which can be concatenated with ~
writeln("d" ~ "lang");
// Integers and floats
writeln("1+1 = ", 1 + 1);
writeln("7.0/3.0 = ", 7.0 / 3.0);
// Booleans, with boolean operators as you'd expect
writeln(true && false);
writeln(true || false);
writeln(!true);
}
To run the program, save it as values.d
and use the D compiler:
$ dmd values.d
$ ./values
dlang
1+1 = 2
7.0/3.0 = 2.33333
false
true
false
In this D program:
We import the
std.stdio
module, which provides input/output functionality.The
main
function is the entry point of the program.String concatenation in D uses the
~
operator instead of+
.The
writeln
function is used for printing to the console, similar tofmt.Println
in the original example.Integer and float operations work similarly to other languages.
Boolean operations are the same as in many other programming languages.
D provides a similar set of basic types and operations as other modern programming languages, making it easy to work with various kinds of data.