Game Development Reference
In-Depth Information
Chapter 2
Writing a Guessing Game
with C++ Types
You will begin the process of learning C++ by learning about the different built-in types that the
language supports. C++ has built-in support for integers, floating point numbers, booleans, and
enumerators. This chapter covers all of these types. We also look at the different types of operators
that can be used to manipulate and compare these types of values. It is useful to understand how
C++ handles variables before we begin to create programs in the language. To start, we take a
look at the difference between dynamically and statically typed languages, which includes how we
declare and define variables in C++.
Dynamic Versus Static Typed Languages
Variables in programming languages can be handled in two different ways. Dynamically typed
languages do not require the programmer to state explicitly which type should be used to store the
value. Dynamically typed languages can switch the type of a variable on the fly depending on how it
is being used.
Statically typed languages require the programmer to tell the compiler explicitly which type to use to
represent the data the variable will store. C++ is a statically typed language and creating variables in
C++ is a two-step process.
Declaring Variables
When we are introducing a new variable into a program, we are said to be declaring the variable.
This essentially means that we are telling the compiler that we would like to have a variable of a
specific type and with a specific name. C++ compilers require that all variables be declared before
they can be used in our programs. An example of a variable declaration would be:
int numberOfObjects;
7
 
Search WWH ::




Custom Search