Full Modern C++ For Absolute Beginners: A Friendly Introduction To The C++ Programming Language and C++11 To C++23 Standards, 2nd Edition Slobodan Dmitrović Ebook All Chapters
Full Modern C++ For Absolute Beginners: A Friendly Introduction To The C++ Programming Language and C++11 To C++23 Standards, 2nd Edition Slobodan Dmitrović Ebook All Chapters
https://ebookmass.com
https://ebookmass.com/product/modern-c-for-absolute-beginners-2nd-
edition-slobodan-dmitrovic/
testbankdeal.com
https://ebookmass.com/product/modern-c-for-absolute-beginners-second-
edition-solbodan-dmitrovic/
testbankdeal.com
https://ebookmass.com/product/c-programming-language-c-programming-
lang-_p2-2nd-edition-ebook-pdf/
testbankdeal.com
C Programming Absolute Beginner’s Guide (3rd Edition)
Perry
https://ebookmass.com/product/c-programming-absolute-beginners-
guide-3rd-edition-perry/
testbankdeal.com
https://ebookmass.com/product/c-programming-for-beginners-by-sett-
john-hafeez-abdulmutolib/
testbankdeal.com
https://ebookmass.com/product/an-introduction-to-programming-through-
c-abhiram-g-ranade/
testbankdeal.com
https://ebookmass.com/product/c-programming-for-dummies-2nd-edition-
dan-gookin/
testbankdeal.com
https://ebookmass.com/product/data-parallel-c-programming-accelerated-
systems-using-c-and-sycl-2nd-edition-james-reinders/
testbankdeal.com
Modern C++ for Absolute
Beginners
A Friendly Introduction to the C++
Programming Language and C++11
to C++23 Standards
Second Edition
Slobodan Dmitrović
Modern C++ for Absolute Beginners: A Friendly Introduction to the C++
Programming Language and C++11 to C++23 Standards
Slobodan Dmitrović
Belgrade, Serbia
Chapter 1: Introduction�������������������������������������������������������������������������������������������� 1
Chapter 5: Types����������������������������������������������������������������������������������������������������� 13
Fundamental Types��������������������������������������������������������������������������������������������������������������������� 13
Boolean���������������������������������������������������������������������������������������������������������������������������������� 13
Character Type����������������������������������������������������������������������������������������������������������������������� 14
Integer Types������������������������������������������������������������������������������������������������������������������������� 16
Floating-Point Types�������������������������������������������������������������������������������������������������������������� 18
Type void������������������������������������������������������������������������������������������������������������������������������� 18
Type Modifiers����������������������������������������������������������������������������������������������������������������������������� 19
Variable Declaration, Definition, and Initialization����������������������������������������������������������������������� 19
v
Table of Contents
Chapter 6: Exercises����������������������������������������������������������������������������������������������� 21
Hello World and Comments��������������������������������������������������������������������������������������������������������� 21
Declaration���������������������������������������������������������������������������������������������������������������������������������� 21
Definition������������������������������������������������������������������������������������������������������������������������������������� 22
Initialization��������������������������������������������������������������������������������������������������������������������������������� 22
Chapter 7: Operators���������������������������������������������������������������������������������������������� 25
Assignment Operator������������������������������������������������������������������������������������������������������������������ 25
Arithmetic Operators������������������������������������������������������������������������������������������������������������������� 25
Compound Assignment Operators���������������������������������������������������������������������������������������������� 27
Increment/Decrement Operators������������������������������������������������������������������������������������������������ 28
Chapter 9: Exercises����������������������������������������������������������������������������������������������� 31
Standard Input���������������������������������������������������������������������������������������������������������������������������� 31
Two Inputs����������������������������������������������������������������������������������������������������������������������������������� 31
Multiple Inputs���������������������������������������������������������������������������������������������������������������������������� 32
Inputs and Arithmetic Operations����������������������������������������������������������������������������������������������� 33
Postincrement and Compound Assignment�������������������������������������������������������������������������������� 33
Integral and Floating-Point Division�������������������������������������������������������������������������������������������� 34
vi
Table of Contents
Substrings����������������������������������������������������������������������������������������������������������������������������������� 48
Finding a Substring��������������������������������������������������������������������������������������������������������������������� 49
vii
Table of Contents
viii
Table of Contents
ix
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Table of Contents
x
Table of Contents
xi
Table of Contents
xii
Table of Contents
std::unordered_set�������������������������������������������������������������������������������������������������������������� 288
std::unordered_map������������������������������������������������������������������������������������������������������������ 290
std::tuple����������������������������������������������������������������������������������������������������������������������������� 292
static_assert������������������������������������������������������������������������������������������������������������������������ 293
Introduction to Concurrency������������������������������������������������������������������������������������������������ 294
Deleted and Defaulted Functions���������������������������������������������������������������������������������������� 301
Type Aliases������������������������������������������������������������������������������������������������������������������������� 304
C++14��������������������������������������������������������������������������������������������������������������������������������������� 304
Binary Literals��������������������������������������������������������������������������������������������������������������������� 305
Digit Separators������������������������������������������������������������������������������������������������������������������� 306
Auto for Functions��������������������������������������������������������������������������������������������������������������� 306
Generic Lambdas����������������������������������������������������������������������������������������������������������������� 307
std::make_unique���������������������������������������������������������������������������������������������������������������� 307
C++17��������������������������������������������������������������������������������������������������������������������������������������� 308
Nested Namespaces������������������������������������������������������������������������������������������������������������ 308
Constexpr Lambdas������������������������������������������������������������������������������������������������������������� 309
Structured Bindings������������������������������������������������������������������������������������������������������������� 309
std::filesystem��������������������������������������������������������������������������������������������������������������������� 311
std::string_view������������������������������������������������������������������������������������������������������������������� 315
std::any�������������������������������������������������������������������������������������������������������������������������������� 317
std::variant�������������������������������������������������������������������������������������������������������������������������� 319
C++20��������������������������������������������������������������������������������������������������������������������������������������� 322
Modules������������������������������������������������������������������������������������������������������������������������������� 323
Concepts������������������������������������������������������������������������������������������������������������������������������ 325
Lambda Templates�������������������������������������������������������������������������������������������������������������� 329
[likely] and [unlikely] Attributes������������������������������������������������������������������������������������������� 330
Ranges��������������������������������������������������������������������������������������������������������������������������������� 332
Coroutines��������������������������������������������������������������������������������������������������������������������������� 336
std::span������������������������������������������������������������������������������������������������������������������������������ 337
Mathematical Constants������������������������������������������������������������������������������������������������������ 338
xiii
Table of Contents
C++23��������������������������������������������������������������������������������������������������������������������������������������� 339
Multidimensional Subscript Operator���������������������������������������������������������������������������������� 340
Literal Suffixes for size_t����������������������������������������������������������������������������������������������������� 340
The #warning Preprocessor Directive��������������������������������������������������������������������������������� 341
The std::string::contains( ) Member Function���������������������������������������������������������������������� 341
std::print������������������������������������������������������������������������������������������������������������������������������ 343
Index��������������������������������������������������������������������������������������������������������������������� 433
xiv
About the Author
Slobodan Dmitrović is a software consultant, trainer, and
author of several programming books. He is a professional
R&D software developer with two decades of experience in
the industry. Slobodan provides C++ training courses for
corporate clients and academic institutions. Connect with
Slobodan at https://www.linkedin.com/in/slobodan-
dmitrovic/.
xv
About the Technical Reviewer
Germán González-Morris is a polyglot software architect/
engineer with 20+ years of experience in the field, having
knowledge in Java, Spring, C, Julia, Python, Haskell, and
JavaScript, among others. He works for cloud (architecture)
and web distributed applications. Germán loves math
puzzles (including reading Knuth), swimming, and table
tennis. Also, he has reviewed several books including an
application container book (WebLogic) and books on
languages (C, Haskell, TypeScript, WebAssembly, Math for
coders, regexp, Julia, Algorithms). For more details, you can
visit his blog (https://devwebcl.blogspot.com/) or Twitter
account (@devwebcl).
xvii
Acknowledgments
I want to thank my friends, readers, and fellow C++ peers who have supported me in
writing the second edition of this book.
I am thankful to the entire C++ community for their help and feedback. I would
like to thank Rainer Grimm, Klaus Iglberger, Jens Weller, Bartłomiej Filipek, and
many others.
My most profound appreciation goes to S. Antonijević, Ron and Brankica, and Saša
Popović for their ongoing support.
xix
About the Second Edition
The second edition of this book is updated to include the notable features inside the
C++23 standard.
I have revised and updated numerous chapters with more relevant information and
clarification.
The second edition includes more diagrams to represent certain concepts better.
I have also added the output for all the code snippets.
The book now has a chapter entirely dedicated to various projects.
My intent with the second edition was to provide a simplified, updated, and accurate
introduction to the modern C++ programming language.
xxi
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
CHAPTER 1
Introduction
Congratulations on choosing to learn the C++ programming language, and thank you for
picking up this book. I will try to introduce you to a beautiful world of C++ to the best of
my abilities.
This book is an effort to introduce the reader to the C++ programming language in
a structured, straightforward, and friendly manner. We will use the “just enough theory
and plenty of examples” approach whenever possible.
To me, C++ is a wonderful product of the human intellect. Over the years, I have
certainly come to think of it as a thing of beauty and elegance. C++ is a language like no
other, surprising in its complexity yet wonderfully sleek and elegant in so many ways. It
is also a language that cannot be learned by guessing, one that is easy to get wrong and
challenging to get right.
In this book, we will get familiar with the language basics first. Then, we will move on
to classes, templates, and the C++ Standard Library. Once we got these covered, we will
describe the modern C++ standards in more detail.
After each section, source code exercises will help us adopt the learned material
more efficiently.
Finally, we will create a couple of source code projects. Let us get started!
1
© Slobodan Dmitrović 2023
S. Dmitrović, Modern C++ for Absolute Beginners, https://doi.org/10.1007/978-1-4842-9274-7_1
CHAPTER 2
What Is C++?
C++ is a programming language – a standardized, general-purpose, object-oriented,
compiled language. Every C++ compiler is accompanied by a set of useful functions
and containers called the C++ Standard Library. Bjarne Stroustrup created C++ as an
extension to a C programming language. Still, C++ evolved to be a completely different
programming language.
Let us emphasize this: C and C++ are two different languages. C++ started as “C with
classes,” but it is now a completely different language. So, C++ is not C; C++ is not C with
classes; it is just C++. And there is no such thing as a C/C++ programming language.
C++ is widely used for so-called systems programming as well as application
programming. C++ is a language that allows us to get down to the metal where we can
perform low-level routines if needed or soar high using abstraction mechanisms such as
templates and classes.
C++ Standards
C++ is governed by the ISO C++ standard. There are multiple ISO C++ standards listed
here in chronological order: C++03, C++11, C++14, C++17, C++20, and the upcoming
C++23 standard.
Every C++ standard, starting with C++11 onward, is referred to as “modern C++.”
And modern C++ is what we will be teaching in this book.
3
© Slobodan Dmitrović 2023
S. Dmitrović, Modern C++ for Absolute Beginners, https://doi.org/10.1007/978-1-4842-9274-7_2
Random documents with unrelated
content Scribd suggests to you:
NATIVE OF BILUCHISTAN.