Literals Solutions - D Programming Language

Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Discord (community-run)
  - Forums
  - IRC
  - Wiki
  - Issues
  - Contributing
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# Literals Solutions

#### Literals Dersi Problem Çözümleri

1. The problem here is that the value on the right-hand side is too large to fit in an `int`. According to the rules about integer literals, its type is `long`. For that reason it doesn't fit the type of the variable on the left-hand side. There are at least two solutions.

   One solution is to leave the type of the variable to the compiler for example by the `auto` keyword:

           auto amount = 10_000_000_000;

   The type of `amount` would be deduced to be `long` from its initial value from the right-hand side.

   Another solution is to make the type of the variable `long` as well:

           long amount = 10_000_000_000;

2. We can take advantage of the special `'\r'` character that takes the printing to the beginning of the line.

       import std.stdio;

       void main() {
           for (int number = 0; ; ++number) {
               write("\rNumber: ", number);
           }
       }

   The output of that program may be erratic due to its interactions with the output buffer. The following program flushes the output buffer and waits for 10 millisecond after each write:

       import std.stdio;
       import core.thread;

       void main() {
           for (int number = 0; ; ++number) {
               write("\rNumber: ", number);
               stdout.flush();
               Thread.sleep(10.msecs);
           }
       }

   Flushing the output is normally not necessary as it is flushed automatically before getting to the next line e.g. by `writeln`, or before reading from `stdin`.

Copyright © 1999-2026 by the D Language Foundation | Page generated by Ddoc on Wed Aug 19 13:28:52 2026