Skip to main content

Introducing Fundamental Types of Data

  • Chapter
  • First Online:
Beginning C++23
  • 1017 Accesses

Abstract

In this chapter, we’ll explain the fundamental data types that are built into C++. You’ll need these in every program. All the object-oriented capabilities are founded on these fundamental data types because all the data types that you create are ultimately defined in terms of the basic numerical data your computer works with. By the end of the chapter, you’ll be able to write a simple C++ program of the traditional form: input – process – output.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 49.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 64.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    If need be, you can determine whether char is signed or not on your platform using the expressions std::is_signed_v<char> (a so-called type trait expression), std::signed_integral<char> (a concept expression; see Chapter 21), or std::numeric_limits<char>::is_signed (see also later in this chapter).

  2. 2.

    You typically compile executables to run on your own computer, or at least on computers with the same basic architecture. But in general you can create executables for other hardware as well (this is called cross-compilation). The target hardware could, for instance, be some mobile or embedded device, supporting significantly different native data types and processor instructions.

  3. 3.

    In the IEEE 754 schema binary floating-point numbers are normalized to the form ±1....e±…. Since the leading bit of these normalized significands is always 1, there is no need to explicitly store it. Note that this is also why the numbers in Table 2-4 seemingly leave no room for the sign bit.

  4. 4.

    The animal formally known as Puma concolor proudly holds the Guinness record for the animal with the highest number of different aliases, with over 40 aliases in the English language alone. It also holds the record for highest jump by a mammal from a standstill (23 ft, or 7 m!).

  5. 5.

    If not combined with u or U, a z or Z suffix defines a literal of the signed integer type with the same size as std::size_t (until further notice, C++ defines no alias for this signed version of std::size_t).

  6. 6.

    These are examples of variable templates, a lesser-used flavor of templates. The principle is the same as with the function and class templates we explain in Chapters 10 and 17.

  7. 7.

    Usually, the rounding behavior of std::round() will suit you just fine. But just so you know, the Standard Library also offers the std::nearbyint() and std::rint() functions for which you can configure the rounding behavior through std::fesetround(). Available options include rounding halfway cases toward zero, toward negative infinity, and so on. You can consult a Standard Library reference for further details in the unlikely event that your need this flexibility.

  8. 8.

    The C standard library also defines the INFINITY and NAN float constants. These don’t become available with import std; (or even with import std.compat;), though, because they are defined in the form of macros (see Appendix A). We therefore recommend you use equivalent C++ constructs instead.

  9. 9.

    For those of you still using C++11 or C++14 compilers, never use braced initializers with auto type deduction because the results are simply too unpredictable. Instead, either explicitly state your variable types or use assignment or functional notation.

  10. 10.

    Granted, “Latin Small Letter Sharp S” in Table 2-13 is perhaps not the best example for selling you on the use of the Unicode name, given that ß is probably better known by its less formal name, “eszett”…

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2023 The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Horton, I., Van Weert, P. (2023). Introducing Fundamental Types of Data. In: Beginning C++23. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-9343-0_2

Download citation

Publish with us

Policies and ethics