We continue our C++ tutorial series. If you haven't read the introduction, click the link below.
C++ For Beginners
All variables to be used in...
For further actions, you may consider blocking this person and/or reporting abuse
No. The standard guarantees only minimum sizes. It also only says that
sizeof(short)
<=sizeof(int)
<=sizeof(long)
. You also left outlong long
.No. They're used to defined floating point numbers. A "decimal number" is a representation of a number in base 10.
No.
char
is used to define only a single character. A "string of characters" is represented by an array ofchar
. You also left outwchar_t
.No. By definition,
sizeof(char)
is always 1, but that number has nothing to do with how many physical bytes of memory it occupies.This is wrong. It needs to be
'f'
in single quotes in order to be achar
.No. They can't be used as names of anything (not only variables). However, they can be used in variable names, e.g.,
character
is a perfectly valid name even thoughchar
is incharacter
.No. This is still a global variable, yet it is inside
{}
:I would suggest that you don't use
{}
as part of your explanation.No. It's
\0
.First of all, thank you for your comment.
1- In your first comment, you commented "No" to the subject you mentioned. What is wrong, I do not understand. Doesn't int and long take up 4 bytes and short 2 bytes? We can even say 8 bytes for long. 4 Byte was for 32-bit operating systems. You also mentioned the long long structure. Here I am preparing a beginner level article. How many times do we use 64 bytes of data at the beginner level?
2- In your second comment, you mentioned decimals. No, your answer is quite ironic. Isn't every number we use used in modular arithmetic 10? Decimal numbers actually mean base 10 numbers anyway.
3- Let's come to your third comment.
char
is not used for just a single letter. Haven't you seen a usage likechar str[4] = "C++"
before? So when usingchar
, we can also use character strings.4- In your fourth comment, we are actually talking about the same thing. Each character of the number you entered will occupy a certain amount of memory. But each unit actually occupies 1 byte of space.
5- You're right about the double quotes here. Habit from different software languages. Let's also tell our friends here that single quotes should be used in single characters. I'm editing this part and thank you for your attention.
6- When writing character, you are not using char anyway. What we're talking about here is just using 'char' or not. To give an example from daily life, there is quite a big difference between the number 10 and the number 1050. We are not breaking the rule just because we used 10 when writing 1050.
7-
Also aren't you going to write any function inside the namespace? As I stated in the text, I am describing the area outside the {} signs of the Function.
8- Yes /0 is an incorrect usage. My fault. Thank you. I am editing.
No. See here and the sentence that begins with "Besides the minimal bit counts, the C++ Standard guarantees that ...."
No. I can use any base I like. C++ directly supports octal (base 8) and hexadecimal (base 16) also.
Yes, I know; but that has nothing to do with floating point numbers.
Yes, it is.
Yes, and that is not a
char
. That's an array ofchar
. They are not the same thing.Your original comment is true only if you restrict your character set to an 7 or 8 bit character set, such as ASCII or EBCIDIC. Other character sets such as Unicode when represented as UTF-16 occupies 2 bytes per character, UTF-32 occupies 4 bytes per character, or UTF-8 occupies 1-to-4 bytes per character. You can't really get away with ignoring Unicode these days.
The guarantee does not mean that they do not take up 4 and 2 bytes of space. There is nothing wrong with my sentence.
Of course, you can use whatever base you want. But the base we use by default is 10. I did not say that C++ does not support other bases. You can easily do simple modular arithmetic in almost any language. So, in fact, there is nothing wrong with this sentence.
Don't we define decimals with floats? Now that I've said that, you're going to say, "No, I can use a double". Please see this answer by Duthomhas in 2010. I'm sure you and I are talking about the same thing.
This does not indicate that it is not a char. String, letter, word etc. inside char. We can fit a lot of things. It should not be thought of as it is written in the books.
You know that being able to generalize and explain things in the simplest way in science and software is a very, very difficult task. If we try to explain all these details and exceptions, it would take a few months to write an article, right? After all, we are talking about languages like C/C++. It's very nice of you to add to the comments and point out some typos. Thank you for this. But you shouldn't call false statements all of them. Because it's true. By saying that you are wrong, you are trying to express that what I wrote is completely wrong and false. I guess it's a software developer disease. "Oh wait, there is actually a situation like this and this expression can also be used like this." I would be much happier if you left a comment like this. Style is an important thing.
But thank you very much for your interest and attitude. We have a lot to learn from you. After all, you are more experienced.
Also yes I have read them all and I want to say "purple" to you. 😄
On your particular machine, they take up that amount of space. That is not universally true.
It's simply not true and repeatedly saying it is doesn't make it so.
No, you define floating-point numbers with
float
,double
, orlong 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:is decimal number. Just because it also happens to have no fractional part doesn't make it not a decimal.
Types and arrays of types simply aren't the same thing. Again, repeating otherwise doesn't make it true.
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:
I would have written:
Please write a C++ textbook that you can fully generalize universally. I promise I will buy first.
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?".
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.
If you had read the first article, you would know that we act on the basis of ASCII.
Then I really don't know why you persist in defending the position that your section title of "Decimal numbers" is correct.
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'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.
By the way:
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?
You may be right about the title. This looks misleading. Thanks.
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.
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.
Decimal vs floatting-point : en.wikipedia.org/wiki/Decimal
en.wikipedia.org/wiki/Floating-poi...
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:
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.
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.