Programming in D Ali Çehreli

Programming in D Ali Çehreli

Programming in D Ali Çehreli Programming in D First Edition Ali Çehreli Edited by Luís Marques Programming in D, First Edition Revision: 2016-04-06 1 The most recent electronic versions of this book are available online2. Copyleft (ɔ) 2009-2015 Ali Çehreli This work is licensed under the Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/. Edited by Luís Marques3 Cover design by İzgi Yapıcı4 Cover illustration by Sarah Reece5 Published by Ali Çehreli6 Fonts: Andada by Carolina Giovagnoli for Huerta Tipográfica Open Sans by Steve Matteson DejaVu Mono by DejaVu Fonts PDF version is generated with Prince XML Other ebook versions are generated with Calibre ISBNs: 978-0-692-59943-3 hardcover by IngramSpark 978-0-692-52957-7 paperback by IngramSpark 978-1-515-07460-1 paperback by CreateSpace 978-1-519-95441-1 ePUB by Draft2Digital 1. https://bitbucket.org/acehreli/ddili 2. http://ddili.org/ders/d.en 3. http://www.luismarques.eu 4. http://izgiyapici.com 5. mailto:[email protected] 6. mailto:[email protected] Contents Foreword by Andrei Alexandrescu xvii Preface xix Acknowledgments .............................................................................................................xix 1. The Hello World Program 1 Compiler installation ............................................................................................................1 Source file...................................................................................................................................1 Compiling the hello world program ...............................................................................1 Compiler switches .................................................................................................................2 IDE................................................................................................................................................ 3 Contents of the hello world program ............................................................................ 3 Exercises ....................................................................................................................................4 2. writeln and write 5 Exercises .................................................................................................................................... 5 3. Compilation 6 Machine code ..........................................................................................................................6 Programming language.......................................................................................................6 Interpreter ................................................................................................................................6 Compiler .................................................................................................................................... 7 4. Fundamental Types 8 Properties of types.................................................................................................................9 size_t ......................................................................................................................................10 Exercise ....................................................................................................................................10 5. Assignment and Order of Evaluation 11 The assignment operation ................................................................................................11 Order of evaluation..............................................................................................................11 Exercise .....................................................................................................................................11 6. Variables 12 Exercise .................................................................................................................................... 13 7. Standard Input and Output Streams 14 Exercise .................................................................................................................................... 14 8. Reading from the Standard Input 15 Skipping the whitespace characters............................................................................ 16 Additional information..................................................................................................... 17 Exercise .................................................................................................................................... 17 9. Logical Expressions 18 Logical Expressions............................................................................................................. 18 Grouping expressions ........................................................................................................ 21 Reading bool input............................................................................................................. 21 Exercises ..................................................................................................................................22 10. if Statement 24 The if block and its scope ...............................................................................................24 The else block and its scope ..........................................................................................24 Always use the scope curly brackets............................................................................25 The "if, else if, else" chain..................................................................................................25 Exercises ..................................................................................................................................27 11. while Loop 28 The continue statement ..................................................................................................28 The break statement..........................................................................................................29 v Infinite loop............................................................................................................................29 Exercises ..................................................................................................................................30 12. Integers and Arithmetic Operations 31 Exercises .................................................................................................................................. 41 13. Floating Point Types 42 Floating point type properties........................................................................................42 .nan ...........................................................................................................................................43 Specifying floating point values....................................................................................43 Overflow is not ignored.....................................................................................................44 Precision..................................................................................................................................45 There is no truncation in division................................................................................45 Which type to use ................................................................................................................46 Cannot represent all values.............................................................................................46 Comparing floating point values...................................................................................47 Exercises ..................................................................................................................................48 14. Arrays 49 Definition ................................................................................................................................49 Containers and elements..................................................................................................50 Accessing the elements......................................................................................................50 Index ..........................................................................................................................................51 Fixed-length arrays vs. dynamic arrays ......................................................................51 Using .length to get or set the number of elements ............................................51 An array example ................................................................................................................52 Initializing the elements...................................................................................................52 Basic array operations....................................................................................................... 53 Exercises .................................................................................................................................. 55 15. Characters 56 History......................................................................................................................................56 Unicode encodings..............................................................................................................57 The character types of D...................................................................................................58

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    758 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us