Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Professional C++ [eng].pdf
Скачиваний:
284
Добавлен:
16.08.2013
Размер:
11.09 Mб
Скачать

C++ Interviews

Things to Remember

Overloading stream operators, because they are the most commonly overloaded operators, and are conceptually unique

What a functor is and how to create one

Choosing between a method operator or a global friend function

Some operators can be expressed in terms of others (i.e., operator<= can be written by negating the result of operator >).

Types of Questions

Let’s face it — operator overloading questions (other than the simple ones) are cruel. Anybody who is asking such questions knows this and is going to be impressed when you get it right. It’s impossible to predict the exact question that you’ll get, but the number of operators is finite. As long as you’ve seen an example of overloading each operator that it makes sense to overload, you’ll do fine!

Besides asking you to implement an overloaded operator, you could be asked high-level questions about overloaded operators. A find-the-bug question could contain an operator that is overloaded to do something that is conceptually wrong for the particular operator. In addition to syntax, keep the use cases and theory of operator overloading in mind.

Chapter 17: Writing Efficient C++

Efficiency questions are quite common in interviews because many organizations are facing scalability issues with their code and need programmers who are savvy about performance.

Things to Remember

Language level efficiency is important, but it can only go so far. Design-level choices are ultimately more significant.

Reference parameters are more efficient because they avoid copying.

Object pools can help avoid the overhead of creating and destroying objects.

Profiling is vital to determine which operations are really consuming the most running time.

Types of Questions

Often, the interviewer will use his own product as an example to drive efficiency questions. Sometimes the interviewer will describe an older design and some performance-related symptoms he experienced. The candidate is supposed to come up with a new design that alleviates the problem. Unfortunately, there is a major problem with questions like this — what are the odds that you’re going to come up with the same solution that the interviewer did when the problem was actually solved? Because the odds are slim, you need to be extra careful to justify your designs. You may not come up with the actual solution, but you can still have an answer that is correct or even better than the company’s newer design.

797

Appendix A

Other types of efficiency questions may ask you to tweak some C++ code for performance or iterate on an algorithm. For example, the interviewer could show you code that contains extraneous copies or inefficient loops.

Chapter 18: Developing Cross-Platform

and Cross-Language Applications

Few programmers submit resumes that list only a single language or technology, and few large applications rely on only a single language or technology. Even if you’re only interviewing for a C++ position, the interviewer can still ask questions about other languages, especially as they relate to C++.

Things to Remember

The ways in which platforms can differ (architecture, sizes, etc.)

The fine line between programming and scripting

The interactions between C++ and other languages

Types of Questions

The most popular cross-language question is to compare and contrast two different languages. You should avoid saying just positive or just negative things about a particular language, even if you really hate Java. The interviewer wants to know that you are able to see tradeoffs and make decisions based on them.

Cross-platform questions are more likely to be asked while discussing previous work. If your resume indicates that you once wrote C++ applications that ran on a custom hardware platform, you should be prepared to talk about the compiler you used and the challenges of that platform.

Chapter 19: Becoming Adept at Testing

Potential employers value strong testing abilities. Because your resume probably doesn’t indicate your testing skills, unless you have explicit QA experience, you might face interview questions about testing.

Things to Remember

The difference between black box and white box testing

The concept of unit testing and writing tests along with code

Techniques for higher-level tests

Testing and QA environments in which you’ve worked before: what worked and what didn’t?

798

C++ Interviews

Types of Questions

An interviewer could ask you to write some tests during the interview, but it’s unlikely that a program presented during an interview would contain the depth necessary for interesting tests. It’s more likely that you will be asked high-level testing questions. Be prepared to describe how testing was done at your last job and what you liked and didn’t like about it. After you answer, this is a good question for you to ask the interviewer. Hopefully, it will start a conversation about testing and give you a better idea of the environment at your potential job.

Chapter 20: Conquering Debugging

Engineering organizations look for candidates who are able to debug both their own code as well as code that they’ve never seen before. Technical interviews often attempt to size up your debugging muscles.

Things to Remember

Debugging doesn’t start when bugs appear; you should instrument your code ahead of time so you’re prepared for the bugs when they arrive

Logs and debuggers are your best tools

The symptom that a bug exhibits may appear to be unrelated to the actual cause

Memory diagrams can be helpful in debugging, especially during an interview

Types of Questions

During an interview, you might be challenged with an obscure debugging problem. Remember that the process is the most important thing, and the interviewer probably knows that. Even if you don’t find the bug during the interview, make sure that the interviewer knows what steps you would go through to track it down. If the interviewer hands you a function and tells you that it crashes when run, he or she should award just as many points to a candidate who properly discusses the sequence of steps to find the bug as to a candidate who finds it right away.

Chapters 21, 22, and 23: The Standard

Template Librar y

As you’ve seen, the STL can be difficult to work with. Few interviewers would expect you to recite the details of STL classes unless you claim to be an STL expert. If you know that the job you’re interviewing for makes heavy use of the STL, you might want to write some STL code the day before to refresh your memory. Otherwise, recalling the high-level design of the STL should suffice.

799

Appendix A

Things to Remember

The different types of containers and their relationships with iterators

Basic usage of vector, which is probably the most frequently used STL class

Usage of associative containers, such as map

The purpose of STL algorithms and some of the built-in algorithms

The ways in which you can extend the STL (details are most likely unnecessary)

Your own opinions about the STL

Types of Questions

If interviewers are dead set on asking detailed STL questions, there really are no bounds to the types of questions they could ask. If you’re feeling uncertain about syntax though, you should state the obvious during the interview — “In real life, of course, I’d look that up in Professional C++, but I’m pretty sure it works like this . . .” At least that way the interviewer is reminded that he or she should forgive the details as long as you get the basic idea right.

High-level questions about the STL are often used to gauge how much you’ve used the STL without making you recall all the details. For example, casual users of the STL are familiar with associative and nonassociative containers. A slightly more advanced user would be able to define an iterator and describe how iterators work with containers. Other high-level questions could ask you about your experience with STL algorithms or whether you’ve customized the STL.

Chapter 24: Exploring Distributed Objects

Because distributed applications are quite common, you might be asked to design a distributed system or answer questions about a particular distributed technology.

Things to Remember

The reasons why distributed computing is used

The difference between distributed and networked computing

The concepts of serialization and RPC

The details of CORBA or XML if you are claiming competence in these technologies

Types of Questions

Many technical resumes are a sea of acronyms and buzzwords. If you list a technology like XML on your resume, a potential employer has no way of knowing your level of expertise. Unless you specifically say “Basic XML skills” or “XML expert,” you can expect questions that are designed to determine where you stand on that continuum. For XML in particular, questions may involve defining terms like schema or hands-on exercises such as writing a schema that applies to a given XML document.

800