Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Another Native Data Type

Another Native Data Type

We've used almost all the native data types, but there is one other native type that you might see in other programs and in other textbooks, so I should tell you about it now. By the way, I haven't avoided this type because it's particularly difficult to use; the reason is simply that it wasn't necessary to the task at hand, which was teaching you how to program, using C++. Now that we have accomplished that task, you might as well add it to your arsenal of tools. This other native type is float, which, like the double type we've already seen, is used to store values that can contain fractional parts, (so-called floating-point numbers). Why are there two of these types rather than only one? The main difference between float and double is that a float is 4 bytes long and a double is 8 bytes long; therefore, a double can store larger values and maintain higher accuracy. However, it also uses twice the amount of memory of a float, which may not be important when we're dealing with a few values but is quite important if we have a vector or array of thousands or tens of thousands of elements.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint