Chapter 2. Creating Data Structures

In This Chapter

  • Discovering all the different data types

  • Casting and converting

  • Using structures with your data

  • Comparing and manipulating structures

C++, being a computer language and all, provides you with a lot of ways to manipulate data — numbers, letters, strings, arrays — anything you can store inside the computer memory. To get the most out of C++, you should know as much as you can about the fundamental data types. This chapter covers them and how to use them.

In this chapter, we refer to the ANSI standard of C++. ANSI is the American National Standards Institute. The information we provide in this chapter deals with the ANSI standard (singular) of C++. Fortunately, the GNU gcc compiler that comes with CodeBlocks is ANSI-standard compliant. (Little nuances show up, but not often.)

Working with Data

In the sections that follow, we tell you how you can manipulate your data, including the types of data available to you and how you can change them.

The great variable roundup

The ANSI C++ standard dictates these fundamental C++ types:

  • char: This is a single character. On most computers, it takes 1 byte.

  • int: This is an integer. On most of the computers in the late 1990s and early 2000s, a single integer takes 4 bytes. With 4 bytes, this gives you a range from −2147483648 to 2147483647.

  • short int: This is a half-sized integer. Just a little 2-byte fellow, which leaves just enough room for −32768 to 32767.

  • long int: You would expect a long int to be longer ...

Get C++ All-In-One For Dummies®, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.