DEV Community

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

 
fkkarakurt profile image
Fatih Küçükkarakurt

Also yes I have read them all and I want to say "purple" to you. 😄

Thread Thread
 
pauljlucas profile image
Paul J. Lucas

The guarantee does not mean that they do not take up 4 and 2 bytes of space.

On your particular machine, they take up that amount of space. That is not universally true.

There is nothing wrong with my sentence.

It's simply not true and repeatedly saying it is doesn't make it so.

Don't we define decimals with floats?

No, you define floating-point numbers with float, double, or long double. You are still confusing the concepts of "bases" with "integer" vs "floating-point." "Floading-point" is its own concept. Your original section title was "Decimal constants"; it should have been "Floating-point constants." This:

int x = 42; // This is also a decimal!
Enter fullscreen mode Exit fullscreen mode

is decimal number. Just because it also happens to have no fractional part doesn't make it not a decimal.

This does not indicate that it is not a char.

Types and arrays of types simply aren't the same thing. Again, repeating otherwise doesn't make it true.

You know that being able to generalize and explain things in the simplest way in science and software is a very, very difficult task.

Yes, but that doesn't mean you state things as fact when they're not. If you initially want to make a simplified statement, you put something like either a parenthetical comment or footnote that explains that it's not strictly true following by a "more later" where you will eventually explain the details. For example, you wrote:

Each character occupies 1 byte of memory.

I would have written:

C++ inherits its primitive types from C. Back when C was invented in 1978, characters (individual letters, numbers, or symbols) were very western-alphabet-centric and so the char type (inherited from C) is only big enough to store a single character from a western alphabet. Today with software being used all over the world by many people who don't use western alphabets, char is woefully inadequate; but for now, we'll make the simplifying assumption that it stores a single character.

Thread Thread
 
fkkarakurt profile image
Fatih Küçükkarakurt

On your particular machine, they take up that amount of space. That is not universally true.

Please write a C++ textbook that you can fully generalize universally. I promise I will buy first.

And yes there is nothing wrong with my sentence. You know this is true. It would take a lot of time to write separate information for 32-bit operating systems or IBM quantum computers, wouldn't it? What you're talking about is "Hey, you know, there are actually some exceptions, for example...". But no, you think it's all wrong. No, everything is not wrong.

No, you define floating-point numbers with float, double, or long double. You are still confusing the concepts of "bases" with "integer" vs "floating-point." "Floading-point" is its own concept. Your original section title was "Decimal constants"; it should have been "Floating-point constants." This:

I already explained float, double, or long double above. Also, I wish you had a look at the link I posted. Of course, I know that 14 and 14.0 are decimal numbers and they are equal to each other. It's pretty easy to break the rules of a programming language. we can print numbers from 1 to 100 without using any loops. So, when describing cycles, "are we going to say you don't need this anyway?".

Types and arrays of types simply aren't the same thing. Again, repeating otherwise doesn't make it true.

Ok, I already said above that "char is used for characters and strings." what is wrong with this sentence? With char we can do it in a list, we can do it in an array, we can also define just one letter. I'll tell you about Arrays and Pointers anyway.

C++ inherits its primitive types from C. Back when C was invented in 1978, characters (individual letters, numbers, or symbols) were very western-alphabet-centric and so the char type (inherited from C) is only big enough to store a single character from a western alphabet. Today with software being used all over the world by many people who don't use western alphabets, char is woefully inadequate; but for now, we'll make the simplifying assumption that it stores a single character.

If you had read the first article, you would know that we act on the basis of ASCII.

Thread Thread
 
pauljlucas profile image
Paul J. Lucas

Of course, I know that 14 and 14.0 are decimal numbers and they are equal to each other.

Then I really don't know why you persist in defending the position that your section title of "Decimal numbers" is correct.

It's pretty easy to break the rules of a programming language. we can print numbers from 1 to 100 without using any loops. So, when describing cycles, "are we going to say you don't need this anyway?".

I really can't follow this; nor do I see what it has to do with the fact that floating-point numbers are correctly called "floating-point numbers" and not "decimal numbers." Really, all you have to do is change the one word of "decimal" to "floating-point" and then your section would be correct. I really don't understand why you are staunchly defending the incorrect term.

If you had read the first article, you would know that we act on the basis of ASCII.

If you're writing for a web audience, you have to expect that people will read things out of order. If you explained earlier what I did, then in this post, you should have put a reminder, perhaps with a link, back the original explanatory text.

Thread Thread
 
pauljlucas profile image
Paul J. Lucas • Edited

By the way:

Please write a C++ textbook that you can fully generalize universally. I promise I will buy first.

There's no need. There are already many excellent C++ textbooks and web sites out there. I don't see the point in writing something that's already done well elsewhere. So I really don't understand the entire purpose of your posts. Even if your posts were 100% correct, what new unique perspective are your posts bringing to the table?

Thread Thread
 
fkkarakurt profile image
Fatih Küçükkarakurt

You may be right about the title. This looks misleading. Thanks.

There's no need. There are already many excellent C++ textbooks and web sites out there. I don't see the point in writing something that's already done well elsewhere. So I really don't understand the entire purpose of your posts. Even if your posts were 100% correct, what new unique perspective are your posts bringing to the table?

Many people are here to learn, to be persistent and to share something. What is not new to you may be new to someone else.

Thread Thread
 
pauljlucas profile image
Paul J. Lucas

Many people are here to learn, to be persistent and to share something. What is not new to you may be new to someone else.

Then write a post recommending an already-written good C++ book; or link to an already-written C++ web series that you've found. Writing yet another series of intro to C++ posts seems like a lot more work when excellent alternatives already exist.

Thread Thread
 
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.