Hint 1: During the early days of the railroads, they had a problem with trains hitting each other where the tracks crossed. So they passed a law:
When two trains approach each other at a place where the rails cross, both shall stop and remain stopped until the other one has proceeded it.
(Answer 24.)
Hint 2: UNIX uses <line-feed> to end lines. Microsoft Windows uses <carriage-return><line-feed>. (Answer 5.)
if (n2 =! 0)
is not doing its job unless its job is to confuse you, in which case it's doing an excellent job. (Next Hint 82. Answer 25.)
Hint 4: The constructor does a proper job of initializing the magic numbers. Or it would if it were called. But everyone knows there is no way to create a variable without calling the constructor. Well, almost everyone. (Next Hint 300. Answer 98.)
Hint 5: What's the difference between simple macros and parameterized macros? (Answer 113.)
Hint 6: Operating system calls are expensive. (Answer 96.)
Hint 8: Tree surgeon's law: Don't cut off the limb on which you are standing. (Next Hint 317. Answer 75.)
Hint 9: The program does not fail on complex instruction set machines such as the 80x86 CPUs, but fails on RISC machines such as Sparcs. It also fails on the Celerity 1000 [1], which is where I found the problem. (Next Hint 143. Answer 52.)
Hint 10: This program reads data one character at a time. It's supposed to write data one character at a time. (Next Hint 102. Answer 99.)
Hint 11: When the programmer tries to set the debugging variable, he gets the error message:
debugging -- no such variable or class
Hint 12: Check the preprocessor output. (Answer 82.)
Hint 13: The g++ compiler issues the warnings:
var.cpp: In function 'int main()':
var.cpp:14: warning: unused variable 'bool remove'
var.cpp:16: warning: the address of 'int remove(const char*)', will always be
'true'
(Answer 35.)
Hint 14: The optimizer feels free to play games with your code. (Answer 114.)
Hint 15: The results are system-dependent. (Next Hint 278. Answer 63.)
Hint 16: M_PI is correct, but the wrong result is printed. (Next Hint 170. Answer 10.)
Hint 17: The comma operator returns the result of the second expression. So the expression 5,9 has the value 9. (Next Hint 348. Answer 86.)
Hint 18: You can't. (Next Hint 344. Answer 80.)
Hint 19: The printf function gets lost and starts making things up. (Next Hint 31. Answer 85.)
Hint 20: The number of times the body of the loop is executed is probably smaller thank you think. (Next Hint 36. Answer 89.)
Hint 21: If you're using MS-DOS, the result depends on the memory model. (Next Hint 130. Answer 21.)
Hint 22: Failure is system-dependent. (Next Hint 9. Answer 52.)
Hint 23: When is the destructor for true_name called? When is the string used? (Answer 30.)
Hint 24: The more functions you call between the call to tmp_name and where you use the results, the more likely you will get a bad result. (Next Hint 85. Answer 18.)
Hint 25: C++ is only partially typesafe. (Next Hint 63. Answer 7.)
Hint 26: Static data is dangerous. (Answer 100.)
Hint 27: Resources required: resource 1, resource2 - or is that resource2, resource1? (Next Hint 1. Answer 24.)
Hint 28: Run the program through the preprocessor. (Next Hint 327. Answer 29.)
Hint 29: How many times is the loop executed? (Next Hint 20. Answer 89.)
Hint 30: Borland compilers let you define at compile time if the default for character variables is signed or unsigned. (Next Hint 60. Answer 8.)
Hint 31: C does not do parameter checking of printf calls. (Next Hint 277. Answer 85.)
Hint 32: The answer depends on who wrote your heap management library. (Answer 77.)
Hint 33: Run the program through the preprocessor and look at the result. (Next Hint 179. Answer 105.)
11072 12627 16262
3157 3664 5034
13605 16307 22366
Hint 35: Preprocessor syntax is not C++ syntax. (Next Hint 284. Answer 82.)
Hint 36: What do we do with result after we compute it? (Next Hint 152. Answer 89.)
Hint 37: Anyone who would program i++++ should be shot. (Next Hint 272. Answer 87.)
counter = = 10;
is a valid C++ statement. It doesn't do anything, but it's valid. (Next Hint 205. Answer 112.)
Hint 39: Can you express 1/3 as a decimal number exactly? Can the computer express 0.1 as a floating-point number exactly? (The answer is the same for both.) (Answer 107.)
Hint 40: The problem is on an earlier line, not line 16. (Next Hint 346. Answer 79.)
Hint 41: height never gets assigned 2. (Next Hint 78. Answer 62.)
Hint 42: The dictionary file is in alphabetical order. (Next Hint 311. Answer 74.)
Hint 43: What does an_array.operator = (an_array) do? (Answer 75.)
Hint 44: Indentation is incorrect. (Next Hint 156. Answer 31.)
Hint 45: The g++ compiler outputs the warning:
semi.cpp: In function 'int main()':
semi.cpp:15: warning: statement with no effect
Hint 46: What you see is what you get — literally. (Next Hint 307. Answer 69.)
One million 1
Hint 48: What happens to the buffer at the end of the function call? (Answer 83.)
Hint 49: The compiler can decide execution order for some multipart statements. (Answer 26.)
Hint 50: This program generates no compiler warning. (Next Hint 318. Answer 20.)
Hint 51: Two problems are related to what is put in struct data. (I know that makes four, but one falls into both categories.) (Answer 71.)
Hint 52: You know what this hint should be, don't you? (Next Hint 207. Answer 42.)
Hint 53: We have two functions that are calling each result in an infinite recursion. Because there are only three member functions, it should not be too hard to figure out which ones are causing the problem. (Next Hint 125. Answer 12.)
Hint 54: Operator precedence. (Answer 49.)
Hint 55: I didn't know that you could put commas in C++ numbers. (Next Hint 335. Answer 44.)
Hint 56: Where's delete called? (Answer 32.)
Hint 57: Double precision is 64 bits. The C standard is to have all floating-point done in double.
All this has nothing to do with the problem. (Incidentally, getting a 64-bit fraction out of a 64-bit floating-point format is a neat trick.) (Next Hint 94. Answer 73.)
Hint 58: 0d is the ASCII for carriage return. (Next Hint 234. Answer 5.)
Hint 59: The g++ compiler issues the warning:
comma.cpp: In function 'int main()':
comma.cpp:12: warning: left-hand operand of comma expression has no effect
Hint 60: The g++ compiler issues the warning:
chff.cpp: In function `int main()':
chff.cpp:13: warning: comparison is always 0 due to limited range of data type
(Answer 8.)
Hint 61: The uncaught exception is of class problem. Honest! (Next Hint 339. Answer 55.)
Hint 62: The character "A" has the integer value 65. The integer value of "A" + 1 is 66. This is related to the output:
A6667
(Answer 45.)
Hint 63: Externs are not typesafe in C++. (Answer 7.)
Hint 64: The fork system call creates a duplicate process with duplicate memory. (Next Hint 252. Answer 50.)
Hint 65: The program dumps core. (Next Hint 282. Answer 115.)
Hint 66: The indentation is off. (Answer 97.)
Hint 67: Don't count on the indentation being correct. (Answer 13.)
Hint 68: What is the exit code returned to the operating system by this program? (Answer 6.)
Hint 69: Results are system-dependent. (Next Hint 279. Answer 94.)
Enter two integers: 100 3
Result is: 100
Enter two integers: 37 0
Result is: 37
Hint 71: The \n character shows up where it's not wanted. (Answer 33.)
Hint 72: The C++ strings handle everything for us. But there's one thing they do behind our back that causes trouble. (Next Hint 162. Answer 36.)
Hint 73: The program dumps core when run. (Next Hint 182. Answer 95.)
Hint 74: On most systems the command:
$ program
will work, and the command:
$ program >output.txt
will fail. (Next Hint 197. Answer 83.)
Hint 75: What type of parameter is out_file? (Next Hint 159. Answer 40.)
Hint 76: In binary, 3 is 0011. In binary, 12 is 1100. (Next Hint 218. Answer 17.)
Hint 77: The error occurs when the open fails. (Next Hint 288. Answer 60.)
11 height = 2;
is not an executable statement; it just looks like one. (Next Hint 287. Answer 62.)
Hint 79: When is a_var initialized and the constructor called? (Next Hint 137. Answer 111.)
Hint 80: Computers don't know basic mathematics. (Next Hint 268. Answer 1.)
Hint 81: No prototypes — no parameter checking. (Next Hint 174. Answer 41.)
Hint 82: The g++ compiler generates the warning:
not_z.cpp: In function `int main()':
not_z.cpp:13: warning: suggest parentheses around assignment used as truth
value
Hint 83: There is one variable declared for the two declarations. (Next Hint 148. Answer 57.)
Hint 84: What's 0x8000 >> 1? (Answer 19.)
Hint 85: What's being pointed to? Who owns it? For how long? (Answer 18.)
Hint 86: Who owns the data being pointed to by each of the pointers. (Next Hint 26. Answer 100.)
Hint 87: Results are system-dependent. (Next Hint 21. Answer 21.)
Hint 88: Where is the data put for the statement:
printf("That's all\n");
Hint 89: This is correct, legal, standard C++ even though it may not look like it to some people. (Next Hint 211. Answer 86.)
Hint 90: Run the output through the preprocessor. (Next Hint 273. Answer 88.)
Hint 91: The g++ compiler gives us a warning:
hbit.cpp: In function 'void bit_out(short int)':
hbit.cpp:19: warning: overflow in implicit constant conversion
(Answer 2.)
Hint 92: It's obvious that the problem must be before line 28 because we don't see the Starting.... message. (Next Hint 111. Answer 68.)
i is 3
i is 2
(Answer 87.)
Hint 94: This is implementation-dependent. On some older systems, you get the proper number of bits accuracy. In general systems that emulate floating-point will report accurate results and systems with floating-point coprocessors will report exaggerated results. (Answer 73.)
Hint 95: The results are compile-time switch-dependent. (Next Hint 331. Answer 39.)
Hint 96: The gcc warnings are:
sum.c: In function 'sum':
sum.c:13: warning: declaration of 'i1' shadows a parameter
sum.c:14: warning: declaration of 'i2' shadows a parameter
sum.c:15: warning: declaration of 'i3' shadows a parameter
(Answer 94.)
Hint 97: Race condition. Ties cause a dead stop. (Next Hint 27. Answer 24.)
Hint 98: remove is a flag.remove is not a flag. (Next Hint 221. Answer 35.)
Hint 99: Humans print the zip code for Boston as 02126. C++ sees things differently. (Next Hint 308. Answer 15.)
Area of sample is 0
Hint 101: This was an old C program ported to C++ by an old C programmer. (Next Hint 120. Answer 98.)
Hint 102: The output looks something like:
47421068117101321161113211511110910132981149710511
01009710997103101100321121141111031149710932114101
11311710511410110910111011611544101161041013210211
...
Hint 103: Results are system-dependent. (Next Hint 314. Answer 90.)
Hint 104: On a MS-DOS system, the Cleveland zip code is a negative number. (Next Hint 223. Answer 104.)
Hint 105: The optimizer can do a lot of work on this code. (Answer 84.)
Hint 106: The g++ compiler issues the warning:
comment.cpp:19:35: warning: "/*" within comment
(Answer 91.)
Hint 107: The results are compile-time switch-dependent. (Next Hint 29. Answer 89.)
Hint 108: What is a buffer? (Next Hint 263. Answer 68.)
Hint 109: What do setjmp and longjmp not do? (Answer 66.)
Hint 110: An exception is not being caught. At first glance, this may seem impossible because there is only one exception class, problem, which we catch. Even if we didn't catch it, the catch(...) should catch everything else. (Next Hint 173. Answer 55.)
Hint 111: Nothing is obvious in programming. (Answer 68.)
Hint 112: It's an off by one error. (Next Hint 227. Answer 38.)
Hint 113: Write 1/3 in decimal. (Next Hint 302. Answer 54.)
Hint 114: It's always the same number each time. (Next Hint 66. Answer 97.)
Hint 115: Two ifs, one else. So which if does the else belong to? (Answer 31.)
Hint 116: The result is system-dependent. You may be lucky and get the right answer, or you may get random numbers. (Answer 51.)
Hint 117: What's the range of a short int? (Answer 1.)
Hint 118: Funny macro definition. (Next Hint 190. Answer 113.)
Hint 119: The bombing is compiler-dependent. On the cheap compilers you get a core dump. The better ones print an error message telling you that you called a pure virtual function. (Next Hint 237. Answer 101.)
Hint 120: There's no way to change a constant in a class. Yet if we run this through the debugger we find that the magic numbers are 0 instead of their intended values. (Next Hint 4. Answer 98.)
Hint 121: The problem is compilation flag-dependent. (Next Hint 14. Answer 114.)
11 squared is 121
not the squares of 1 to 10 as the programmer expected. (Answer 34.)
Hint 123: The item printed is not an integer. (Next Hint 149. Answer 86.)
Hint 124: The variable ch is a character. What is ch+1? (Next Hint 283. Answer 45.)
Hint 125: Count the number of times the copy constructor is called. (Next Hint 235. Answer 12.)
Hint 126: "000" is a legal C++ statement. Totally useless, but legal. (Answer 44.)
Hint 127: Yes, buffered I/O is useful to a program like this. But not the way it's done here even though we're using the buffered I/O library iostream. (Answer 65.)
Hint 128: How many times is the multiply being done? (Answer 39.)
Hint 129: The results can depend on what compiler flags are used at compile time. (Next Hint 310. Answer 9.)
Hint 130: Intel machines have a very brain-damaged segmented pointer architecture. (Next Hint 231. Answer 21.)
Hint 131: Results are compiler-dependent. (Next Hint 141. Answer 8.)
Hint 132: A process switch can occur at any time. (Next Hint 276. Answer 92.)
Hint 133: The preprocessor is not C++. (Next Hint 360. Answer 46.)
if (i = = 2)
i=1;
else
i = 2;
But there's a faster method. (Next Hint 140. Answer 48.)
Hint 135: The answer is system-dependent. (Next Hint 264. Answer 70.)
Hint 136: Octal. (Answer 15.)
Hint 137: When is std::cout initialized? (Answer 111.)
comment.cpp:11: warning: '/*' within comment
(Answer 62.)
Hint 139: I expected the program to print:
First 1
First 1
First 1
Second 1
Second 2
Second 3
This is not what was printed. (Next Hint 297. Answer 102.)
Hint 140: Here's another method:
i = (i == 2) ? 1 : 2;
But there's a faster method. (Next Hint 216. Answer 48.)
Hint 141: Results can be changed by compile-time switches on some compilers. (Next Hint 30. Answer 8.)
Hint 142: Constructors for a derived class are called in the order "base, derived." Destructors are called in the order "derived, base." (Answer 101.)
flags |= CD_SIGNAL;
is supposed to set a single bit in flags. Most of the time it does so. (Answer 52.)
----------------
Hint 145: What is the type of variable being passed in? What is the parameter type as far as the function is concerned? (Next Hint 315. Answer 72.)
Hint 146: The C++ std::string class allocates memory. But it also destroys it and is carefully designed to avoid memory leaks. (Next Hint 359. Answer 66.)
Hint 147: Some compilers, including the one used for this program, let you optimize and debug. (Next Hint 11. Answer 84.)
Hint 148: The g++ issues the warning:
/tmp/cckuUagE.o: In function 'std::string::_M_data() const':
/home/sdo/local/include/g++-v3/i586-pc-linux-gnu/bits/gthr-
single.h(.data+0x0): multiple definition of 'value'
/tmp/ccenmAbd.o(.data+0x0):/home/sdo/local/include/g++-v3/i586-pc-linux-gnu/
bits/gthr-single.h: first defined here
collect2: ld returned 1 exit status
(Answer 57.)
Hint 149: The item printed is a pointer. (Next Hint 347. Answer 86.)
Hint 150: When does the string first_name get initialized? When does full_name? Who enforces that order? (Answer 3.)
Hint 151: '\n' is newline. (Answer 37.)
Hint 152: If we do nothing with result, then why bother to compute it? (Answer 89.)
struct info *new_info(void)
contains a clue. (Next Hint 101. Answer 98.)
Hint 154: How many pointers are there? How many things are they pointing to? (Next Hint 209. Answer 64.)
Hint 155: The g++ compiler outputs the warning:
equal.cpp: In function 'int main()':
equal.cpp:15: warning: suggest parentheses around assignment used as truth value
Customer must pay -10
Hint 157: Your results may vary. (Next Hint 79. Answer 111.)
Hint 158: SAIL and C share almost no syntax. The two languages are entirely different. Yet the same single-character mistake is responsible for both programs going wrong. (Next Hint 220. Answer 53.)
Hint 159: Normally C++ uses "pass by value" to pass parameters. That means that the value is copied into the subroutine. (Next Hint 233. Answer 40.)
Hint 160: The output contains a bunch of integers. (Answer 99.)
Hint 161: I count 3. (Next Hint 293. Answer 71.)
Hint 162: This looks a lot like Program 58. (Next Hint 178. Answer 36.)
Hint 163: What does ++i return? What does i++ return? (Next Hint 93. Answer 87.)
Hint 164: Your results may vary. (Next Hint 19. Answer 85.)
Hint 165: Everyone knows that (x*4)/4 = x. That is basic mathematics. (Next Hint 80. Answer 1.)
Hint 166: If you think the compile time switches have to do with optimization, you're wrong. (Next Hint 358. Answer 63.)
Hint 167: What numbers can be represented by a 3-bit signed number? (Next Hint 169. Answer 42.)
Division 5
Hint 169: What numbers can be represented by a 2-bit signed number? (Next Hint 52. Answer 42.)
pi is 1413754136
Results are machine-dependent. (Next Hint 203. Answer 10.)
Hint 171: All bit arrays are not the same size. (Next Hint 353. Answer 56.)
Hint 172: What you see is what you get. (Next Hint 46. Answer 69.)
Hint 173: So where does the uncaught exception come from? (Next Hint 61. Answer 55.)
Hint 174: gcc produced the warnings:
strcat.c: In function `full_name':
strcat.c:19: warning: implicit declaration of function `strcpy'
strcat.c:20: warning: implicit declaration of function `strcat'
strcat.c:20: warning: passing arg 2 of `strcat' makes pointer from integer witho
ut a cast
strcat.c: In function `main':
strcat.c:28: warning: implicit declaration of function `printf'
(Answer 41.)
Hint 175: The statement is absolutely useless if the program is run normally. (Next Hint 232. Answer 80.)
Hint 176: Your results may vary. (Next Hint 24. Answer 18.)
Hint 177: Results are system- and compiler-dependent. (Next Hint 49. Answer 26.)
Hint 178: This is a C++ version of the error in Program 58. (Answer 36.)
Hint 179: The ABORT statement looks like a statement. It's not. (Answer 105.)
-xxxxxxxxxxxxxxx
Hint 181: Where does scanf leave the file when it stops reading? (Answer 28.)
Hint 182: The program dumps core when doing the sscanf. (Next Hint 254. Answer 95.)
Hint 183: Is buffered I/O useful in this case? (Next Hint 213. Answer 65.)
Hint 184: The problem involves the overuse of delete. (Next Hint 188. Answer 115.)
Hint 185: We don't always close the file after opening it. The result is that we run out of file descriptors. We need to add some close(fd) statements. (That's 2 of the 3 problems.) (Answer 60.)
Hint 186: The program uses inline with functions that someone points to. Can that be part of the problem? (Next Hint 219. Answer 77.)
Hint 187: There's what looks like a useless semicolon at the end of:
result=result/*divisor; /* Do divide */;
It's not useless. (Next Hint 245. Answer 91.)
Hint 188: The operator delete is used in the copy constructor. What's being deleted? (Answer 115.)
Hint 189: How many instances of the an_array variable are there? (Next Hint 329. Answer 59.)
Hint 190: Run it through the preprocessor. (Next Hint 5. Answer 113.)
Hint 191: What is being returned? (Next Hint 23. Answer 30.)
Hint 192: The output is system-dependent. (Next Hint 90. Answer 88.)
Hint 193: The indentation is not correct. (Next Hint 122. Answer 34.)
Hint 194: The results are system-dependent. (Next Hint 324. Answer 112.)
Hint 195: prev_ch is created a lot. (Answer 106.)
Hint 196: What's modified by volatile? (Answer 61.)
Hint 197: The setbuf causes the data to be put where? (Next Hint 88. Answer 83.)
Hint 198: M_PI is defined in math.h as
#define M_PI 3.14159265358979323846 /* pi */
Hint 199: What does the function:
trouble operator = (const trouble &i_trouble)
return? (Next Hint 333. Answer 109.)
Hint 200: It does not print what's expected. (Next Hint 192. Answer 88.)
The area is 367
Hint 202: So why does the division not happen? (Next Hint 187. Answer 91.)
Hint 203: The g++ compiler reports the warnings:
pi.c: In function 'main':
pi.c:12: warning: int format, double arg (arg 2)
(Answer 10.)
Y=8
Hint 205: MAX is not 10. (Answer 112.)
Hint 206: The printing is correct as far as C++ is concerned. (Next Hint 99. Answer 15.)
Hint 207: The g++ compiler issues the warning:
bit.cpp: In function 'int main()':
bit.cpp:33: warning: comparison is always 0 due to width of bitfield
(Answer 42.)
$ equal
Enter current balance: 10
You owe 0
$ equal
Enter current balance: 0
You owe 0
$ equal
Enter current balance: -10
You owe 0
Hint 209: There is only one name variable and two pointers. (Answer 64.)
Hint 210: In what order are the constant members initialized? (Next Hint 100. Answer 93.)
Hint 211: The results are system-dependent. (Next Hint 123. Answer 86.)
Hint 212: Results are system-dependent. (Next Hint 225. Answer 110.)
Hint 213: Is buffered I/O used in this case? (Next Hint 127. Answer 65.)
Hint 214: Obviously, it prints Hello once and two new lines. But it is equally obvious it wouldn't be in this book if it did the sane thing. (Next Hint 64. Answer 50.)
Hint 215: It looks like there is a comment on line 10 and a comment on line 11. That's not quite right. There's a comment on lines 10 and 11. (Next Hint 138. Answer 62.)
Hint 216: The fastest method uses no comparison and one subtraction. (Answer 48.)
Hint 217: The program outputs:
Error: Could not open
oot
ewable
Hint 218: "Bitwise And" is not "Logical And". (Answer 17.)
Hint 219: The program uses inline with functions that someone points to. Can that be part of the problem? No. That has nothing to do with it. C++ handles this situation just fine. (Next Hint 271. Answer 77.)
Hint 220: If this were a cipher a frequency analysis of the numbers might provide a clue. Actually this is not a cipher, but a frequency analysis of the digits can prove interesting. (Next Hint 341. Answer 53.)
Hint 221: remove is two things. (Next Hint 13. Answer 35.)
Hint 222: Race condition. (Next Hint 132. Answer 92.)
Hint 223: Most UNIX compilers use 32 bits for an integer. On MS-DOS (and I mean MS-DOS, not Microsoft Windows), integers are usually 16 bits. (Next Hint 258. Answer 104.)
% calc
Enter operator and value:+ 5
Total: 5
Enter operator and value:+ 10
Bad operator entered
Total: 5
Enter operator and value:Bad operator entered
Total: 5
Enter operator and value :q
Bad operator entered
Total: 5
Enter operator and value:q
Hint 225: What do you think it takes to get the log_file initialized? (Answer 110.)
Hint 226: There are no less than three errors in this program, all of a similar nature. (Next Hint 77. Answer 60.)
Hint 227: What happens if the balance is 0. (Answer 38.)
Hint 228: This program compiles and works on all the known C++ compilers. Yet it is wrong! How can that be? (Next Hint 321. Answer 66.)
Hint 229: The byte after 09 is wrong. (Next Hint 58. Answer 5.)
Hint 230: Alignment and padding. (Next Hint 249. Answer 103.)
Hint 231: On Intel machines, in some memory models, the compiler generates code to manipulate only the address part of a pointer and leaves the segment alone. (Answer 21.)
Hint 232: The statement is useful only if you run the program in an interactive debugger. (Next Hint 309. Answer 81.)
Hint 233: What does it mean to copy an ostream variable? (Answer 40.)
Hint 234: 0a is the ASCII for line feed. (Next Hint 2. Answer 5.)
Hint 235: The copy constructor is called in two places. (Answer 12.)
Hint 236: How many times is var_array::~var_array called? (Next Hint 286. Answer 59.)
Hint 237: The compiler works very hard to keep you from calling a pure virtual function. You can't declare an instance of an abstract class, and any base class must have a derived version that defines all the pure virtual functions. That means that any pure virtual function will have a real definition in the base class.
So how did we manage to call one if we know that there must be an implementation of the virtual function in the derived class? (Next Hint 142. Answer 101.)
Hint 238: Common sense tells you that if you declare an array as
int array[5]
then the elements are:
array[l], array[2], array[3], array[4], array[5]
Common sense has nothing to do with programming. (Answer 90.)
Hint 239: The following is a hex dump of the MS-DOS output:
000000 00 01 02 03 04 05 06 07 08 09 0d 0a 0b 0c 0d 0e
000010 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e
000020 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e
000030 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e
000040 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e
000050 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e
000060 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e
000070 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e
000080 7f
Hint 240: Comma is a C++ operator. (Next Hint 47. Answer 44.)
Hint 241: Thread switching can occur between any two lines like these two:
++count; // We've got a new character
*in_ptr = ch;// Store the character
(Answer 92.)
Hint 242: The g++ compiler reports the warning:
def.cpp: In function 'int main()':
def.cpp:19: warning: label 'defualt' defined but not used
(Answer 67.)
Hint 243: On UNIX, name is 15 characters long. On MS-DOS, it's only 12 characters long. (Next Hint 151. Answer 37.)
Hint 244: Using g++ when the program is compiled.
g++ -g -Wall -o last last.cpp first.cpp
it works. But when compiled as:
g++ -g -Wall -o last first.cpp last.cpp
it fails.
Hint 245: If you have syntax highlighting in your editor, see what happens when you put this code into it. (Next Hint 338. Answer 91.)
Hint 246: It's obvious that the answer is 3. (i++ is 2 and one more ++ makes 3.) But nothing's obvious in programming. (Next Hint 37. Answer 87.)
Hint 247: Spacing. (Next Hint 325. Answer 23.)
Hint 248: There are two variable declarations in this program. (Next Hint 83. Answer 57.)
Hint 249: 6 is not divisible by 4. (Answer 103.)
Hint 250: The redefined new function should work because it's obvious that all bit arrays are the same size. (Next Hint 171. Answer 56.)
Hint 251: Watch your end. (Answer 43.)
Hint 252: The fork system call creates a duplicate process with duplicate memory, and that includes printf data that has been buffered. (Answer 50.)
Hint 253: Normal people count five things by saying, "1, 2, 3, 4, 5." C++ programmers say, "0, 1, 2, 3, 4." (Next Hint 238. Answer 90.)
calc2.c: In function 'main':
calc2.c:24: warning: format argument is not a pointer (arg 3)
calc2.c:24: warning: format argument is not a pointer (arg 4)
(Answer 95.)
Hint 255: The preprocessor does not understand C++ syntax. (Next Hint 295. Answer 78.)
Hint 256: The problem usually goes away if you try to debug the program. (Next Hint 121. Answer 114.)
Hint 257: Your results may vary. (Next Hint 181. Answer 28.)
Hint 258: A 16-bit integer can go from 32767 to -32768. (Answer 104.)
Hint 259: The result is 367 (330 + 37). (Answer 29.)
Hint 260: strcmp does not return true/false. (Answer 76.)
Hint 261: char prev_ch = '\0'; is executed when prev_ch is created. (Next Hint 195. Answer 106.)
if (n2 =! 0)
change n2. (Answer 25.)
Hint 263: The UNIX designers in their infinite wisdom issue the message:
Floating exception (core dumped)
for an integer divide by zero. (Next Hint 92. Answer 68.)
Hint 264: Some systems let you dereference NULL; others do not. (Answer 70.)
Hint 265: Not in this book! (Next Hint 72. Answer 36.)
Hint 266: The expression x << 2 is really 4. However, we don't use this expression in this program. (Next Hint 204. Answer 49.)
if (amount = 0)
does not compare 0 and amount. (Answer 47.)
Hint 268: The output of this program is:
The number of sheep is: 100
The number of sheep is: 1000
The number of sheep is: -6384
Hint 269: char * != char[] (Next Hint 25. Answer 7.)
Size is 25
not
Size is 20
as the programmer expected. (Answer 4.)
Hint 271: The answer is system-dependent. (Next Hint 32. Answer 77.)
Hint 272: Should it be infeasible to shoot him or her, the person should be enlightened as to what good programming style is. (Next Hint 163. Answer 87.)
Hint 273: The output on one system looks like:
3 squared is 9
5 squared is 25
7 squared is 49
9 squared is 81
11 squared is 121
(Answer 88.)
Hint 274: The switch statement does not have a default case; it just looks like it. (Next Hint 242. Answer 67.)
Hint 275: There's nothing wrong with line 16. We asked about it to fool you. (Next Hint 40. Answer 79.)
Hint 276: The reader performs these two lines:
++count; // We've got a new character
*in_ptr = ch;// Store the character
two.c: In function 'main':
two.c:11: warning: too few arguments for format
two.c:9: warning: unused variable `answer'
(Answer 85.)
Hint 278: Some compilers have a switch that will change the behavior of the program. The switch won't fix things, but the program will act differently. (Next Hint 166. Answer 63.)
Hint 279: There's more than one i1. (Next Hint 96. Answer 94.)
Hint 280: Know the difference between "and" and "and and". (Next Hint 76. Answer 17.)
Result is 0
(Answer 27.)
Hint 282: If you examine the code, I always make sure to delete the variable data before I overwrite it. (Next Hint 184. Answer 115.)
A6667
-1.0;
is a good C++ statement. Although totally useless, the statement is perfectly legal. (Next Hint 12. Answer 82.)
Hint 285: Because there are no headers, we have no prototypes for the standard functions; they are declared implicitly. (Next Hint 81. Answer 41.)
Hint 286: var_array::~var_array is called twice. (Answer 59.)
Hint 287: If you have an editor with syntax coloring, it will display base in one color and height in another. (Next Hint 215. Answer 62.)
Hint 288: The open fails even when the file is present and the permissions allow the reading of the file. (Next Hint 306. Answer 60.)
int &i = 3+4;
is illegal. But don't worry; we don't use it - at least not in this form. (Answer 22.)
Width is too small
area(10, 10) = 100
What the programmer expected is:
Width is too small
area(10, 50) = 500
Hint 291: The copy constructor is called more than you might think. (Next Hint 316. Answer 109.)
Hint 292: Remember "1" is not the same as "1.0". (Next Hint 281. Answer 27.)
Hint 293: Two problems involve the number of bytes in struct data. (Next Hint 51. Answer 71.)
Hint 294: strcmp can confuse a novice. (Next Hint 260. Answer 76.)
Hint 295: Run the output through the preprocessor. (Answer 78.)
Stack 0 has 1 elements
Stack 1 has 100 elements
Stack 2 has 134516168 elements
Stack 3 has 134525376 elements
Stack 4 has 4 elements
Hint 297: What is the value of i++? What is the value of ++i? (Answer 102.)
Hint 298: They're different. (Next Hint 255. Answer 78.)
Hint 299: The numbers appear to be octal. (Answer 53.)
Hint 300: It's impossible to change a constant inside a class, yet this program does. It's impossible to create a class without calling the constructor, yet this program does. (Answer 98.)
Hint 301: This program prints:
parity
-break
xon
-rts
(Answer 108.)
Hint 302: Write 1/3 in decimal three times in a column. Now add them up. (Answer 54.)
Hint 303: 0x8000 (1000 0000 0000(b)) is (1<<15). That's the correct value and what the programmer expected. (Next Hint 84. Answer 19.)
Hint 304: Indentation is incorrect. (Next Hint 270. Answer 4.)
Hint 305: Making your own new function can speed up things greatly — if you do it right. (Next Hint 250. Answer 56.)
Hint 306: The open fails with an EMFILE error. (The process already has the maximum number of files open.) (Next Hint 185. Answer 60.)
"Hello World!/n"
contains 14 characters. (Answer 69.)
San Diego 92126
Boston 01110
Hint 309: The programmer thinks that something funny is happening when data item #500 is read. (Answer 81.)
Hint 310: How many times is *in_port_ptr read? (Next Hint 356. Answer 9.)
Hint 311: The data structure used is an unbalanced binary tree. (Next Hint 323. Answer 74.)
Hint 312: I didn't know you could do triple comparisons like a<b<c. (Next Hint 18. Answer 80.)
Hint 313: A character has 8 bits. What are their numbers? (Answer 11.)
Hint 314: Sometimes when you run the program you get the wrong answer, sometimes you dump core with a segmentation violation (Windows users will get a UAE - Unexpected Application Error), and sometimes things work just fine. (Next Hint 253. Answer 90.)
Hint 315: What's the size of the element of the arrays? (Answer 72.)
sizeof(stack) != sizeof(safe_stack)
Copy Constructor called
= operator called
Copy Constructor called
= operator called
Copy Constructor called
= operator called
...
(Next Hint 199. Answer 109.)
Hint 317: This program tries to copy data just after it deletes it. (Next Hint 43. Answer 75.)
Hint 318: What are the arguments to memset? (Next Hint 337. Answer 20.)
Hint 319: Results are system-dependent. (Next Hint 191. Answer 30.)
Hint 320: There's a reason that we didn't include any headers in this program. (Next Hint 285. Answer 41.)
Hint 321: The program is nonstandard. (Next Hint 68. Answer 6.)
Hint 322: Hey, isn't this the program we just did in Program 58? No, actually it's the program you just did with a fix applied. Notice the nice static declaration on line 22. (But it's still got problems.) (Next Hint 154. Answer 64.)
Hint 323: The data structure used is a very unbalanced binary tree. (Answer 74.)
Hint 324: Check the preprocessor output. (Next Hint 38. Answer 112.)
Hint 325: This program needs "blank", "blank", and "blank". (Answer 23.)
Hint 326: The g++ compiler reports the warning:
rect.cpp: In constructor `rectangle::rectangle(int, int)':
rect.cpp:20: warning: member initializers for 'const int rectangle::height'
rect.cpp:18: warning: and 'const int rectangle::area'
rect.cpp:31: warning: will be re-ordered to match declaration order
(Answer 93.)
Hint 327: The preprocessor follows its own rules. (Next Hint 201. Answer 29.)
Hint 328: What is out_file? (Next Hint 75. Answer 40.)
Hint 329: There are two instances of the var_array class when store_it is executing. (Next Hint 355. Answer 59.)
Hint 330: When a function is not defined in the derived class, C++ will go to the base class for it.
So what stops C++ from calling base::print_it(int)? (Answer 58.)
Hint 331: We do store the result of the multiplication into result 1863 times. So the loop is being executed. (Next Hint 128. Answer 39.)
Hint 332: What's the number of the leftmost bit of a 16-bit word? (Next Hint 144. Answer 2.)
Hint 333: How does the operator = function return its result? (Answer 109.)
Hint 334: The assignment operator has a problem. (Next Hint 357. Answer 14.)
Hint 335: You can't. (Next Hint 240. Answer 44.)
Hint 336: There are things and pointers to things. (Next Hint 196. Answer 61.)
Hint 337: sizeof(array) is not a character and '\0' is not an integer. C++ is not smart enough to notice this. (Answer 20.)
Hint 338: Comments begin with /* and end with */. (Next Hint 106. Answer 91.)
Hint 339: It's the second time we throw the exception that is the problem. (Next Hint 345. Answer 55.)
Hint 340: There's more to a name than you may think. (Next Hint 71. Answer 33.)
Hint 341: If you did the frequency analysis, you would find that the digits 8 and 9 are missing from the output. (Next Hint 299. Answer 53.)
Hint 342:12 * 34 = 408. It always is 408. Everyone knows this, including the compiler. (Answer 16.)
Hint 343: Alignment. (Next Hint 230. Answer 103.)
Hint 344: Why does the computer perform the test 1>c? (Answer 80.)
Hint 345: The second exception is thrown from the stack destructor. (Answer 55.)
Hint 346: The problem is on line 5. (Answer 79.)
Hint 347: The g++ compiler issues the warning:
array2.cpp: In function 'int main()':
array2.cpp:17: warning: left-hand operand of comma expression has no effect
Hint 348: matrix [2] is a pointer. (Answer 86.)
Hint 349: The MS-DOS version inserts one character. (Next Hint 239. Answer 5.)
Hint 350: The problem is compiler-dependent. (Next Hint 256. Answer 114.)
At least one number is zero.
Hint 352: The program reports 64 bits of accuracy. (Next Hint 57. Answer 73.)
Hint 353: There's a reason the redefined new function is passed size as a parameter. (Answer 56.)
2 is prime
3 is prime
5 is prime
7 is prime
We expected a bunch of messages telling us that 4, 6, 8, and 9 are not prime. But for some reason those messages have disappeared.
Hint 355: How is the copy constructor implemented? (Next Hint 236. Answer 59.)
Hint 356: How many times does *in_port_ptr have to be read for the code to work? (At least on the surface level.) (Answer 9.)
Hint 357: What's being assigned by
save_queue = a_queue
(Answer 14.)
Hint 358: The compile-time switches have to do with how the conversion of char to int is handled. (Answer 63.)
Hint 359: What do setjmp and longjmp do? (Next Hint 109. Answer 66.)
Hint 360: Run it through the preprocessor. (Answer 46.)
Hint 361: Hey, Steve, can't you get this program right? (Next Hint 265. Answer 36.)
[1]The Celerity 1000 was one of the first RISC minicomputers. Unfortunately the company that created it is no longer in business.