Function factorial
has been declared to receive a parameter of type unsigned long
and return a result of type unsigned long
. This is shorthand notation for unsigned long int
. The C++ standard requires that a variable of type unsigned long int
be at least as big as an int
.
Typically, an unsigned long int
is stored in at least four bytes (32 bits); such a variable can hold a value in the range 0 to at least 4,294,967,295. (The data type long int
is also typically stored in at least four bytes and can hold a value at least in the range –2,147,483,647 to 2,147,483,647.) As can be seen in Fig. 6.27, factorial values become large quickly. We chose the data type unsigned long
so that the program can calculate factorials greater than 7! on computers with small (such as two-byte) integers. Unfortunately, the function factorial
produces large values so quickly that even unsigned long
does not help us compute many factorial values before even the size of an unsigned long
variable is exceeded.