Literals are values of variables that cannot be changed after definition. They are fixed by programmers during the creation of code.
We have five types of literals in D programming:
In this shot we would focus on the String literal.
Strings literals are a sequence of character wrapped in double ""
, they are analogous to plain characters, escape sequences, or universal characters.
String literals are also used to break long lines of multiline text. Let’s see an example.
import std.stdio; int main(string[] args) { writeln(" Greetings From a Fellow Developer "); return 0; }
In line 4 we have used the writeln
method that allows us to easily output our string in multiple lines. The println
would throw an error when you try to output a string in multiple lines. In the example above, the writeln
is serving as a string literal that helps to allow a new line of a long text.
RELATED TAGS
CONTRIBUTOR
View all Courses