Programmer interview guide 3: a large number of errors (50 +) correction table

Source: Internet
Author: User
Tags define find

A large number of Error Correction forms in programmer interview guide version 3rd

I used to flip it over without writing this article. Now I have recorded it after reading it. Most of the students looking for a job will read the "Programmer Interview Guide". You can simply read it. However, I still need to point out a large number of errors recorded by myself to avoid mistakes. This book is full of errors and has poor editing quality. Although it was repeatedly circulated in another version, there was no error table, and many errors were changed.

Therefore, remind readers to use their own brains. Otherwise, many incorrect expressions and ideas are rooted in your mind and may cause serious consequences. Moreover, this book is too utilitarian and belongs to fast-food knowledge. It is superficial and may create an illusion of its own thoughts and ideas. For example, the preface is true. It is a preface. Friends who are not deeply involved may not see xuanjicang or a gorgeous marketing. When you turn the preface to the second page, you will see a large signature, followed by a large Microsoft tag, and a long string of signatures and positions. That's right, it's almost a page. These many jobs may give a lot of illusion to friends who are not deeply involved. Just like "I studied at Caltech and got a doctorate", I just switched around in California, then I got a doctorate diploma at pheasant University.

Of course, I do not deny the significance of this book. It just browsed some questions that may be encountered during the interview and can help you review what you need to know. As a result, we will list about 50 errors that we have recorded at will for your reference only. There are also some that have not been found, are not considered, or are too lazy to write them out. You are welcome to supplement and exchange them (kayven, hilyhoo@gmail.com ).

C/C ++ Programming

This part mainly involves understanding, details, common applications, and some experience and skills of language concepts.

Example 1

The parsing process expression and logic error do not indicate the true cause of the result 250. The statement "the final result should be 2, but the vs2008 result is 250" is far-fetched and logic-free, the results of any c ++ program are theoretically definite (including undefined is also an answer, and compiler implementation is also an exact answer. For example, the local variable int
I is not initialized, so its value is undefined and will not be determined by the compiler. For example, the size of sizeof (INT) is determined by the compiler and the machine, it cannot be said that because the compilation result is 4 or 4), it won't be the result of the compiler. if the language is not defined, it will be called not defined. If it is implemented by the compiler, It will be implemented by the compiler, it won't be said because of the compiler's results. The C/C ++ language is self-complete, self-compatible, and self-expressed.

This is the case ,~ During operation A, the integer type of A is upgraded. A is unsigned, and the left side is supplemented with 0 (generally, the machine is 32 bits, char is 8 bits, and the left side is 24 bits; if the 16-bit int is used, 8 zeros are added on the left. If the inverse is used, 1 is left, and 1 on the right is shifted to the right (arithmetic shift). Then, the system reads the result according to the unsigned, 250.

P39, interview Example 3 in section 5.5

"The result is half of the same bits of X and Y." The result is the same bit, that is, half of the sum of the same bits.

P40, interview Example 1 in section 5.6

Solution 1: a-B may overflow. This should be proposed. solution 2 is the same. What should I do if I consider overflow? You can make relevant judgments, or consider bitwise operations combined with Boolean logical mathematical formulas, such as power distribution.

P41, Chapter 2 interview Example 2

"What is the use of the header file ifndef/define/endif?", to be precise, it is a type of Conditional compilation, except that the header file is prevented from being repeatedly referenced (overall ), it also prevents repeated definitions (variables, macros, or structures ).

P43, 5.8 interview examples

Remove the comments in C/C ++. 1) it is impossible to comment in single quotes. Of course, this does not affect the result. 2) The program only considers the situation where the quotation mark is preceded by \. If it is two \ s, that is, an error occurs when the backslash is escaped. 3) if a newline connector is not taken into account, an error occurs.

P45, interview Example 1 in section 6.1

Macro definition # define find (struc, e) (size_t) & (struc *) 0)-> E), followed by the operator will be wrong, in addition, the question code is too bad.

P47, interview Example 1 in section 6.2

In C, const modifies Read-Only variables rather than constants. The problem Parsing is confused with C ++. This is a conceptual misunderstanding. Only Enum and # define constants.

P47, Chapter 2 interview Example 2

C ++ does not allow non-type declarations.

P47, Section 3 interview Example 3

Instead of using mutable modifiers in the const member function, the const member function can be modified only when mutable is used for member variables.

P48, interview Example 1 in section 6.3

The parsing is confusing, and the expression is obscure. A major analysis fails to grasp the key points. For example, "A1, A2, and A3 are two bytes. If the structure alignment parameters are 8 bytes aligned by default, A1, A2, and A3 are both two bytes aligned ". In VC, the struct is aligned with the longest number of bytes of the element, and adjacent elements can be placed continuously (the order may be adjusted if special optimization is performed ). In general but incomplete terms, each element can be read at a time. However, by default, the GCC compiler is 4-byte aligned and the maximum value is 4 bytes.

P56, Chapter 7 interview Example 7

1) sizeof (string) does not specify the size. The 4 given in resolution is only an implementation. 2) size0f (* P) * 2/sizeof (string), this code is complicated. * P is of the string type, and the array size is known and hard-coded here, therefore, dividing the array size by the size of a single string is confusing.

P59, 6.4 interview Example 9

Inline functions are not mandatory because they are embedded by the compiler. The main advantages are type check, readability, and debugging. It is important to evaluate the parameters only once, instead of replacing the macro, which prevents the macro from multiple operation errors. In addition, the idea of "no return value is written" in the comment is confusing and mixed, rather than reflecting the difference between inline and macro.

P61, Chapter 1 interview Example 1

It is not because reference is required for variables not to be null. There is no such causal relationship. It is only because the reference can not be checked. What's more, it is reflected in the variable immutable, which has different meanings and functions.

P67, Chapter 3 interview Example 3

Char * C does not assign a global array, but is allocated when the String constant is compiled. c allocates a pointer variable on the stack.

P72, interview Example 1 in section 7.3

The difference between a const pointer and a pointer to a const.

P70, Chapter 7 interview Example 7

1) This is an incorrect saying that "_ A of Class B overwrites _ A of Class A". Pay attention to the scope of the variables of the base class and the derived class. This can be said to be hidden, but not overwritten. 2) construct Class B objects and call the constructor of Class A first. Therefore, Class A's _ A is 1, and Class B's _ A is 2. no causal relationship is resolved.

P83, Chapter 1 interview Example 1

1) the code is too messy, and the recursion uses two layers of loops. The code is similar to one page and two columns. 2) parsing has nothing to do with the Code. Instead of constructing a multi-tree, it is just a loop comparison. 3) const is not used, and there are too many parameters. For more information, see my example.

/***************************************************************** Contact: Kayven 

P85, Chapter 3 interview Example 3

The question is too confusing, that is, how many times X (int n) can be called by this program, not the design algorithm. In the parsing, "single-computing x (9) is of course 9" is too perfunctory.

P87, Chapter 2 interview Example 2

Int ** A = (int *) malloc (N * sizeof (INT) obfuscated int and int1. Although the result may be the same, it is a logical error. Sizeof (INT) and sizeof (int *) have different meanings.

P88, Section 3 interview Example 3 extension

The algorithms listed in the table have almost no improvement on the results and are only half compared. This question does need to be combined with the idea of fast sorting and binary search, but it can change the time complexity (the given algorithm has not changed ).

P92, interview Example 1 in section 8.5

Rand_max * rand_max in the Code is out of bounds. Considering this overflow, the result of the Code should be about 500.

P94, Chapter 1 interview Example 1

This document is not correct. distance is used to implement vector. This is just a vector.

P96, Section 3 interview Example 3

It is useless for code to get a bunch of iterators. In many cases, this is worse than the layout of the copied and pasted code on the Internet.

P98, Section 3 interview Example 3

1) T * array requires const, which is missing. 2) t n, N is not of the T type and should be Int.

P105, Chapter 2 interview Example 2

"Test B () is incorrect because it does not need to be pre-assigned." Where is the pre-assigned value? What is pre-assigned value? No pre-assigned value is required. Resolution is confusing.

P108, Chapter 4 interview Example 4

A () {const int size = 9;} at this time, size is not a member variable and changes the meaning of the question.

P115, interview Example 4 in section 10.5

"Option B can be considered a polymorphism in GCC testing." This is a lot of ambiguous expressions, indicating that they are not understood. The returned class pointer can be different because of the covariant of the returned type. Therefore, this is a multi-state. It is not called "yes" or "It is counted as" under GCC ".

P120, Chapter 1 interview Example 1

The constructor X (A, B) should be X (A), y (B)

P125, Chapter 1 interview Example 1

The translation was too bad and I did not make it clear after several pages of analysis. Understand what you mean.

D option, which cannot be accessed by subclass of the derived class.

Option B can be inherited, but cannot be accessed.

P130, interview Example 1 in section 11.3

I did not need a linked list, but I also chose B. In addition, not every object has a table, multiple inheritance can be performed, and multiple virtual inheritance can also be performed in VC.

P131, Chapter 2 interview Example 2

(2) (3) the resolution is chaotic and incorrect, although the answer is that. First, it depends on the compiler. Second, in parsing, (2) There are more arrays and virtual class pointers, not more virtual function table pointers.

P135, Chapter 4 interview Example 4

The actual address of Pb is part B of the parent class C, not a subclass.

P144, interview example 2 in section 11.7

A lot of useless descriptions did not point out the key points. This question is about conversion functions. It is a special operator overload, special member function, no return type, no parameter, it is recommended to use const modification.

P135, Chapter 4 interview Example 4


Data Structure and Algorithm, Almost all codes are not carefully edited, checked, and checked. The layout is messy. The variable name and function name are very handy, and the program logic is full of loopholes. There is a lot of useless code. I will not list these low-level ones one by one. Several major errors are as follows:

P167, interview Example 1 in section 13.1

In node * Create (), the malloc head is not released. There are a lot of unnecessary operations, such as if before while is useless.

P167, interview example 2 in section 13.1

If P1 is null, It is not determined that the linked list header is confused with the linked list node.

P167, interview Example 7 in section 13.1

This part of the code is basically shoddy, a lot of irrelevant code, null judgment is insufficient, variables are not used, and space for malloc is not released.

P224, Chapter 3 interview Example 3

The second char is Ch, And the parsing is incorrect. The results have nothing to do with 256, 257, and so on. Because 127 + 1 is a negative number less than 255, it is always circulating. It is not about changing the value of 256 char.

P225, 14.4 interview Example 2

B is obviously wrong. Even if const is added to C, the problem is that C is required. Only C ++ can.

P226, 14.5 interview Example 2

The program outputs repeated results rather than the longest length. There are many such errors.

P228, interview Example 5 in section 14.5

The Code was written on one and a half pages. Refer to my code. Of course not necessarily very good, welcome to correct (kayven, hilyhoo@gmail.com)

/***************************************************************** Contact: Kayven 

P230, 14.6 interview examples

1) strlen (reschar) is not the current string length, because only rescahr [0] is set to '\ 0', and the following is not cleared, so the code result is unknown. You can use memset to clear the data. 2) the code in the question uses C ++, so you can use cou to solve a lot of obfuscation between C and C ++ code. The style is very poor. Rather than using sprintf. 3) If STR [k] = STR [k + 1] Count ++; error, this part does not need, just need to loop to the len-2.

There are still a lot to mention. This is a marketing book, and it will be useful if you think more and practice more. It will be harmful if you stick to some ideas and resolutions of this book. Listing errors here is also for your reference. I may not have found any or have no other points of view. Please add.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.