Skip over navigation

Getting Started in C++

Problems

Data Types

How to Cite This SparkNote

Problem : Why are there different data types?

Different data types are used for different types of values. If you are trying to represent something with discrete values (i.e. something you might count), integers are usually useful. If the numbers require a broader range, then long integers, which take up more space in memory, are better. If a variable can have fractional or real values, then floating point or double precision numbers will be useful.

Problem : Why use escape sequences?

Some characters cannot be represented by a symbol on the keyboard. Escape sequences let you easily indicate special characters, such as new lines and backspaces.

Problem : What is the difference between a signed data type and an unsigned data type?

Variables are usually signed, which means they can take on both positive ad negative values. Unsigned variables are always positive, but their positive range is twice as large.

Problem : Why should you use constant variables?

Constant variables are good for constants that will be used repeatedly, as they are clearer and allow for modification. If you decide you want constant variable E to be 2.7 and you later change your mind and want it equal to 2.71828, it is a simple matter of changing the definition of E. If you just used the number, you would have to modify the value 2.7 everywhere it appears in your program.

Problem : How are enumerated types useful?

Enumerated types are used to create new data types that have a finite range of possible values. A color type lends itself to an enum definition with values such as {RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, PURPLE}.

Follow Us