DEV Community

Discussion on: Data Types, Variables and Constants in C++

 
fkkarakurt profile image
Fatih Küçükkarakurt

Thank you. And I hope you didn't think I was taking a harsh stance. I want you to know that I will benefit from your experience. I've already started reviewing most of your projects in your Github Repo.

Thread Thread
 
pgradot profile image
Pierre Gradot • Edited

Decimal vs floatting-point : en.wikipedia.org/wiki/Decimal

The decimal numeral system (also called the base-ten positional numeral system, and occasionally called denary /ˈdiːnəri/[1] or decanary) is the standard system for denoting integer and non-integer numbers.

en.wikipedia.org/wiki/Floating-poi...

In computing, floating-point arithmetic (FP) is arithmetic using formulaic representation of real numbers as an approximation to support a trade-off between range and precision.

Can we say that 3.14 is a decimal number and that in the expression float a = 3.14 uses a decimal number to initialize a floatting-point variable?


About sizes of integral types:

The <int> and <long> data types occupy 4 bytes of memory, and the <short> data types occupy 2 bytes.

This is true on most modern computers, with the most common toolchains. This is not guaranteed in C++ for every CPU with every toolchain. See stackoverflow.com/questions/589575... for more details.

Thread Thread
 
pauljlucas profile image
Paul J. Lucas

There's a distinction between the numeric value and how that value is expressed or printed. 3.14 is a floating-point number printed in a base 10, that is using decimal digits. However, the same floating point number can also be printed in any arbitrary base, e.g., base 2 (using binary digits), base 8 (using octal digits), or base 16 (using hexadecimal digits). For example, see here. Not that neither C nor C++ supports any "point" other than a decimal point, but that doesn't invalidate the concepts.