I l @ ve RuBoard |
Here are groups of one or more macros followed by a source code line that uses them. What code results in each case? Is it valid code?
#define FPM 5280 /* feet per mile */ dist = FPM * miles;
#define FEET 4 #define POD FEET + FEET plort = FEET * POD;
#define SIX = 6; nex = SIX;
#define NEW(X) X + 5 y = NEW(y); berg = NEW(berg) * lob; est = NEW(berg) / NEW(y); nilp = lob * NEW(-berg);
Fix the definition in 1.d. to make it more reliable.
Define a macro function that returns the minimum of two values.
Replace the even_gt() macro in Listing 16.4 with a macro of your own devising.
Define a macro function that prints the representations and the values of two integer expressions. For example, it might print
3+4 is 7 and 4*12 is 48
if its arguments are 3+4 and 4*12 .
Create #define statements to accomplish the following goals:
Create a named constant of value 25 .
Have SPACE represent the space character.
Have PS() represent printing the space character.
Have BIG(X) represent adding 3 to X .
Have SUMSQ(X,Y) represent the sums of the squares of X and Y .
Define a macro that prints the name , value, and address of an int variable in the following format:
name: fop; value: 23; address: ff464016
Suppose you have a block of code you want to skip over temporarily while testing a program. How can you do so without actually removing the code from the file?
How would you create an enumerated type days that makes the abbreviations sun , mon , tue , wed , thu , fri , and sat stand for the integers 0 “6? For the integers 1 “7?
How would you create a variable visit of that type?
What's wrong with this program?
#include <stdio.h> int main(int argc, char argv[]) { printf("The square root of %f is %f\n", argv[1], sqrt(argv[1]) ); }
Suppose scores is an array of 1000 int values that you want to sort into descending order. You will use qsort () and a comparison function called comp() .
What is a suitable call to qsort() ?
What is a suitable definition for comp() ?
How could you dynamically allot space to hold an array of structures?
I l @ ve RuBoard |