简体   繁体   中英

C++ variable arrays

I'm learning C++, and by that I mean I've not made to page 20. However, I think I may have found a typo in the source material*, which naturally confuses and complicates the situation.

Without embarrassing the author further, I'll just say they write:

An array is a variable that can store multiple items of data - unlike a regular array, which can store one piece of data.

I know what an array and variable is. That's not my question. In the interest of clarification and learning, can I confirm that should read:

... - unlike a regular variable , which can store one piece of data.

Which makes sense to me.

*pun intended

Yes.

Let's forget anything we know about C++. Then an array cannot be "unlike a regular array". There definitely is a typo in this sentence.

We cannot know for sure what the author wanted to say, but your suggestion is an obvious one (assuming we remember again what we know about arrays and variables):

An array is a variable that can store multiple items of data - unlike a regular variable , which can store one piece of data.

This still isn't a very good explanation. It can be slightly misleading to say a variable of eg type std::string holds one piece of data (as it contains many characters, a size and possibly more). On the other hand, as someone suggested in a comment one could say that even a std::string (or an array) holds one piece of data just that this "one piece" happens to be a collection of things. Anyhow, the sentence is a bit sloppy and maybe it is not worth trying to interpret it too much.

yes array can store multiple (similar kinds of in c++) data unlike a variable which will store only one piece of data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM