Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d programming

What are string literals in D programming?

Chinweuba Elijah Azubuike

What are literals?

Literals are values of variables that cannot be changed after definition. They are fixed by programmers during the creation of code.

Types of literals in D

We have five types of literals in D programming:

  1. Integer Numeral
  2. Floating point Numerals
  3. Characters
  4. Strings
  5. Boolean value.

In this shot we would focus on the String literal.

What are string literals?

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;
String literal example

Code explanation

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.


d programming


Chinweuba Elijah Azubuike

View all Courses

Keep Exploring