Если вы программист C# и хотите попробовать свои силы на вакансиях в международных компаниях уровня Google, Facebook, Apple, Uber, или Microsoft, посмотрите, справитесь ли вы с базовыми тестовыми техническими вопросами, которые задают соискателем на собеседовании в таких компаниях.

Как пройти собеседование на программиста

Вот несколько практических советов:

  1. Собеседование программист должен пройти на английском, поэтому лучше потренировать ответы, чтобы языковой барьер не снизил впечатления о ваших технических знаниях во время интервью. Если ваш язык далек от совершенства, честно предупредите об этом в начале собеседования и попросите максимально простыми словами задавать уточняющие вопросы. Для многих международных компаний самое важное — это ваши технические знания, поскольку язык вы сможете достаточно быстро подтянуть в первый год работы зарубежном.

Подготовитесь не только к техническим вопросам, но и к мотивационным вопросам типа:

  • Почему Вы хотите работать в нашей компании?
  • Что Вас привлекает в работе программиста?

2. Вспомните не только практику, но и теорию. Задания на собеседовании программиста часто включают вопросы на знание теории программирования.

3. Будьте готовы к вопросу о ваших зарплатных ожиданиях. Аналитика по уровню заработных плат программистов по миру, поможет вас сориентироваться, каковы реалистичные ожидания.

Примеры вопросов на собеседовании для программистов C#pastedGraphic.pngpastedGraphic_1.png

  • What are the major differences between C and C++? 
  • What are the differences between new and malloc?
  • What is the difference between delete and delete[]?
  • What are the differences between a struct in C and in C++?
  • What are the advantages/disadvantages of using #define?
  • What are the advantages/disadvantages of using inline and const?
  • What is the difference between a pointer and a reference?
  • When would you use a pointer? A reference?
  • What does it mean to take the address of a reference?
  • What does it mean to declare a function or variable as static?
  • What is the order of initalization for data?
  • What is name mangling/name decoration?
  • What kind of problems does name mangling cause?
  • How do you work around them?
  • What is a class?
  • What are the differences between a struct and a class in C++?
  • What is the difference between public, private, protected, and friend access?
  • For class CFoo { }; what default methods will the compiler generate for you>?
  • How can you force the compiler to not generate them?
  • What is the purpose of a constructor? Destructor?
  • What is a constructor initializer list?
  • When must you use a constructor initializer list?
  • What is a:
    • Constructor? 
    • Destructor? 
    • Default constructor? 
    • Copy constructor? 
    • Conversion constructor? 
  • What does it mean to declare a… 
    • member function as virtual? 
    • member function as static? 
    • member variable as static? 
    • destructor as static? 
  • Can you explain the term «resource acquisition is initialization?» 
  • What is a «pure virtual» member function?
  • What is the difference between public, private, and protected inheritance?
  • What is virtual inheritance?
  • What is placement new?
  • What is the difference between operator new and the new operator?
  • What is exception handling?
  • Explain what happens when an exception is thrown in C++.
  • What happens if an exception is not caught?
  • What happens if an exception is throws from an object’s constructor?
  • What happens if an exception is throws from an object’s destructor?
  • What are the costs and benefits of using exceptions?
  • When would you choose to return an error code rather than throw an exception?
  • What is a template?
  • What is partial specialization or template specialization?
  • How can you force instantiation of a template?
  • What is an iterator?
  • What is an algorithm (in terms of the STL/C++ standard library)?
  • What is std::auto_ptr?
  • What is wrong with this statement?  std::auto_ptr ptr(new char[10]);
  • It is possible to build a C++ compiler on top of a C compiler. How would you do this?
  • What is a vtbl ? 
  • What is RTTI and why do you need it? 
  • How do I specialize a template? Give an example. 
  • What is a partial template? Why would you use one? 
  • How to I create a binary functor in the STL? 

Пример задачи на собеседовании для программиста С

class A;

class B;

class C {

 A* a_;

 B* b_;

 

public:

 C() : a_(nullptr), b(nullptr) {}

 ~C() {

 delete a_;

 delete b_;

};

Implement a copy constructor and assignment operator for C. 

Вариант правильного ответа на вопрос:

class C {

private:

 A* a_;

 B* b_;

 

 void swap(C &rhs) {

 std::swap(a_, rhs.a_);

 std::swap(b_, rhs.b_);

 }

 

public:

 C()…

 ~C()…

 

 C(const C& rhs) : a_(nullptr), b_(nullptr) {

 auto a = std::make_unique<A>(*rhs.a_);

 auto b = std::make_unique<B>(*rhs.b_):

 

 a_ = a.release();

 b_ = b.release();

 }

 

 C &operator=(const C &rhs) {

 C temp(rhs);

 swap(temp);

 return *this;

 }

 };

Пример задачи на собеседовании для программиста С

What is wrong with this class, assuming that this is its complete interface? 

 class C {

 char *p;

 public:

 C() { p = new char[64]; strcpy(p, «Hello world»); }

 ~C() { delete p; }

 

 void foo() { cout << «My ptr is: ‘» << p << «‘» << endl; }

 };

Правильный ответ: copy ctor and assignment operator must either be private (and not implemented) or they must be public and implemented. Since this has an overtly programmed destructor, the memberwise semantics for destruction are not good enough; therefore, they are not good enough for copy and assignment either. But, the copy ctor and op= are not programmed, so we will have some serious trouble. 

Пример задачи на собеседовании для программиста С

Write code that emulates the standard atoi function? 

На что интервьюеры будут обращать внимание в ходе выполнения задания:

  • Do you correctly handle termination conditions? A good candidate will ask for specifics. All candidates should be on the look out for the end of string. 
  • Do you correctly handle edge cases: empty strings, strings with no digits, NULL strings? 
  • Do you look for negative numbers and handle them correctly? 
  • Do you do any tokenization (the standard atoi skips leading white space, for instance)? 
  • Did you make the input argument const (as it should be)? 
  • Do you correctly handle input with non-numerical characters? (for example atoi returns 12 if the input is «12a34») If they don’t do it at first, can they handle it when you remind them that this is how atoi should behave? 
  • Do you correctly convert characters to numbers? (e.g. ‘9’ — ‘0’ = 9) 

Дополнительные вопросы:

How would you rewrite the function to handle errors (the standard function doesn’t do any error checking)? 

  • What sort of errors would you look for? Good answers include: strings with no digits and integer overflow (this one’s fun to pursue, to see what they can do with it). 
  • Can you make your implementation more efficient? 
  • How can you add support for bases other than 10? 
  • Re-implement the function as a small state machine (this is also a fun one). 

Пример задачи на собеседовании для программиста С

Вопрос: How would this code sample handle the string: ‘123-43-6-7’? Is this the same as atoi?) 

int atoi(const char* s)

{

    int val = 0;

    int is_neg = 0;

    if(s == NULL) return val;

    while(isspace(*s)) s++;

    if(*s == ‘-‘) {

        is_neg = 1;

        s++;

    }

    while(isdigit(*s)) {

        val *= 10;

        val += *s — ‘0’;

        s++;

    }

    return is_neg ? -val : val;

}

Вопрос: Where’s the defect in the above sample? A: it doesn’t handle a leading ‘+’ sign. —It also doesn’t handle MININT, -2147483648.) 

Пример задачи на собеседовании для программиста С

Write a function that converts an int into its alpha-numeric equivalent represented as a null terminated string. The function should accept an int as input and return a string as output. For instance, calling the function with an int value of 324 would return a null terminated string containing «324». Ensure that your function checks for appropriate boundary conditions and edge cases. Assume you cannot use any standard libraries (for example, no itoa or sprintf). 

Пример задачи на собеседовании для программиста С

Write a program which has a function which recursively finds the sum of all integers between 0 and some integer. The program should pass the numeric equivalent of each integer command line argument to this function. For example, if you ran «sum 0 5», you should see 0 and 15 as the output. If any command line argument is not an integer, the program should write an appropriate error message to the console. 

Пример задачи на собеседовании для программиста С

Given 

 typedef int T[3];

and two versions of function B 

 // v1 of B

 void B (T z)  { z[0]=1; }

 // v2 of B

 void B (T &z) { z[0]=100; }

and two versions of function A 

 // v1 of A

 void A (T y)  { B(y); }

 // v2 of A

 void A (T &y) { B(y); }

and one version of main 

 int main() {

     T x;

     x[0]= 0;

     A(x);

     return x[0];

 }

Consider each of the four cases. Does it compile? If not, why doesn’t it? What does that version mean? What does main return for that version? 

Ответ: b2 + a1 doesn’t compile

The answer makes more sense if you use the following slightly modified version of the above program: 

#include <iostream>

typedef char T[3];

#define A_VERSION 1

#define B_VERSION 1

#if B_VERSION == 1

void B(T z)  { std::cout << «sizeof(z) = » << sizeof(z) << std::endl; z[0]=’1′; }

#else

void B(T &z) { std::cout << «sizeof(z) = » << sizeof(z) << std::endl; z[0]=’2′; }

#endif

#if A_VERSION == 1

void A(T y)  { std::cout << «sizeof(y) = » << sizeof(y) << std::endl; B(y); }

#else

void A(T &y) { std::cout << «sizeof(y) = » << sizeof(y) << std::endl; B(y); }

#endif

int main() {

    std::cout << «sizeof(char) = » << sizeof(char) << std::endl;

    T x;

    std::cout << «sizeof(x) = » << sizeof(x) << std::endl;

    x[0]= ‘0’;

    A(x);

    std::cout << x[0] << std::endl;

    return 0;

}

0.5