Programming and Graphics

(Kiana) #1

4.5 Functions with scalar arguments 107


serves to specify the number and type of arguments. The alternative declaration


int ipow (int a, int b)

is also acceptable, whereaandbare two irrelevant variables serving the role
or name-holders.


A makefile that compiles the files and links them into an executable
namedbitsreads:


bits: bits.o ipow.o
g++ -o bits bits.o ipow.o
ipow.o: ipow.cc
g++ -c ipow.cc
bits.o: bits.cc
g++ -c c bits.cc

The executable is built by issuing the Unix command:


make bits

and is subsequently run by issuing the command


./bits

A typical session follows:


Will compute the greatest integer
that can be described with n bits

Please enter the number of bits
(should be less than 32)
q to quit
------------------------------
31
bits increment largest integer
111
223
347
4815
51631
63263
7 64 127
8 128 255
9 256 511
10 512 1023
11 1024 2047
Free download pdf