It's programming time!/C++/Data types

From Create Your Own Story


These are the different data types. Of course, you can create your own, but I won't cover that here, since, well, you would create and name it...

For reference, 1 bit = either on or off.

1 byte = 8 bits, meaning you can have each of them on or off.


A little clarification on a byte. Each additional bit (1) doubles the amount of options.

So, 1 bit means you have two options:

0

1

Such as: Do I have my keys? Yes/No. Two choices.

2 bits means you have 22 options:

00

01

10

11

So, do I have my keys + know where my scooter is? 00 = no keys, no knowledge of scooter location. 01 = no keys, but I know where my scooter is. 10 = keys, but no idea where my scooter is, and 11 = I have my keys, and know where my scooter is, so I can go shopping! Now, anyone have some money to donate to this worthy cause?

3 bits, you have 23 options (2x2x2=8), 4 bits, 24 (2x2x2x2)

So, each time it will double. 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc.


Type Keyword Bit width
Boolean bool 1 bit
Character char 1 byte
Integer int 4 bytes
Floating point float 4 bytes
Double floating point double 8 bytes
Valueless void 0
Wide character wchar_t 2 or 4 bytes

There are also four additional options you can select with these (Well, with some):

  • signed = Can have both positive and negative numbers
  • unsigned = Can only have positive numbers
  • short = half the normal bytes allocated to the integer
  • long = Harder to explain. This is used when you may want an integer longer than the standard integer. It will be OS dependent. Basically, in modern computers, all ints are converted to long to allow data overflow.
Personal tools