EXERCISES SECTION 2.3
Exercise 2.11: Write a program that prompts the user to input two numbers, the base and exponent. Print the result of raising the base to the power of the exponent.
KEY CONCEPT: STRONG STATIC TYPING
C++(www.cppentry.com) is a statically typed language, which means that types are checked at compile time. The process by which types are checked is referred to as type-checking.
In most languages, the type of an object constrains the operations that the object can perform. If the type does not support a given operation, then an object of that type cannot perform that operation.
In C++(www.cppentry.com), whether an operation is legal or not is checked at compile time. When we write an expression, the compiler checks that the objects used in the expression are used in ways that are defined by the type of the objects. If not, the compiler generates an error message; an executable file is not produced.
As our programs, and the types we use, get more complicated, we’ll see that static type checking helps find bugs in our programs earlier. A consequence of static checking is that the type of every entity used in our programs must be known to the compiler.
Hence, we must define the type of a variable before we can use that variable in our programs.