Luxoft Sweden | SDE | June2022 | Accepted

Interview: June2022

R1

Open online editor and code and write code.

R2

C++: volatile, overriding vs overloading, Lambda function, C++14 concepts

R3

Example 1

my_struct_t *bar;
/* ... */
memset(bar, 0, sizeof(bar));
—————————————————————————————————————————

Example 2
int i = 5;
int j = i++;
—————————————————————————————————————————

Example 3
unsigned char half_limit = 150;
for (unsigned char i = 0; i < 2 * half_limit; ++i)
{
    // do something;
}
—————————————————————————————————————————

Example 4:                 //Diamond Problem. C,B should be virtual
#include <iostream>
class D {
public:
    void foo() {
        std::cout << "Foooooo" << std::endl;
    }
};
class C:  public D {
};
class B:  public D {
};
class A: public B, public C {
};

int main(int argc, const char * argv[]) {
    A a;
    a.foo();
}
___________________________________________

Example 5:         //What's wrong? Base class ctr need to be virtual
class A
{
public:
  A() {}
  ~A(){}
};

class B: public A
{
public:
  B():A(){}
  ~B(){}
};

int main(void)
{
  A* a = new B();
  delete a;
}


—————————————————————————————————————————

Example 6
class A {
    int a;
    B ob; 
public:
    A (int i,const B &b) : a(i), ob(b)
    {
    }
};




class A {
    int a;
    B ob; 
public:
    A (int i,const B &b)    {
        this->a= i; 
        this->ob= b;
    }
};

————————————————————————————————————————

Example 7:                   //unique_ptr not copy construtible, its move constructible
#include <memory>
auto f(std::unique_ptr<int> ptr) {
  *ptr = 42;
  return ptr;
}

int main() {
  auto ptr = std::make_unique<int>();
  ptr = f(ptr);
}


—————————————————————————————————————————


Example 8
void compute(std::unique_ptr<int[]> p) { ... } 
int main() {
    std::unique_ptr<int[]> ptr = std::make_unique<int[]>(1024);
    std::unique_ptr<int[]> ptr_copy = ptr;
    compute(ptr);
}

—————————————————————————————————————————
Comments (2)