联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2020-10-28 10:44

C++ quiz

[ATTENTION]

1) All questions are single choice by default, except for those marked multiple choices.


1. Which module is not in the common layer?   (   )      

A. DB

B. Functions

C. TX/RX module

D. Trace, eLog



2. Which is not correct about the common layer?    (    )          

A. common layer Contains classes that are used by other layers, math functions, frameworks, etc.

B. All layers can depend on common layer

C. Modules in Common layer have dependencies to other layers

D. DB belongs to the common layer



3. The best way to get the control Hardware info in Service layer or above layers is? (   )  

A. define a macro of control Hardware info in service layer directly

B. create a new interface to read from the DB.

C. Communicate with hardware directly

D. All above



4. Which interface is not in the O&M layer?  (    )  

A. TRDCI

B. RMCI

C. RFTI

D. Fault Manager



5. [Multiple choice] Find out all the right modules that belong to Common layer.  (    )

A. RMCI

B. TRDCI

C. Libraries

D. DB


6.  Regarding modern language features, which one of below options is not preferred? (    )

A. std::string

B. static_cast

C. typedef

D. new, delete



7.  which one of below options is preferred in the new language features? (    )

A. struct

B. new []

C. nullptr

D. iterators




8.  Which option about variable definition is correct? (    )

A. uint16_t m_deviceId;

B. Carrier_v1* m_lrciCarrier;

C. double pi {3.14};

D. None of the above



9.  [Multiple choice] What are the correct descriptions about C++ standard library header files? (    )

A. Use the official header without a .h.

B. The legacy .h files do not place their symbols in the std namespace.

C. Using legacy .h may lead to unexpected behavior.

D. None of the above.



10.  Which is not preferred way to define the array? (    )

A. char ccPortName[8][4];

B. static constexpr std::array<uint8_t, 5> NCPSEC_G{4, 5, 6, 5, 16}

C. std::array<uint32_t, m_numAuxAdcs> m_auxAdcCfg;

D. None of the above.



11.  [Multiple choice] Which ones are the correct description about Naming rules? (    )

A. Use understandable names, avoid abbreviations.

B. A name is either a single word or a concatenation of words.

C. Type names shall begin with a lower-case letter.

D. File names shall begin with a lower-case letter.



12.  Which below description is incorrect for goto? (    )

A. Usage of goto shall be avoided.

B. The goto complicates the code.

C. If it is needed, goto is recommended.



13.  Which of following description regarding lvalue and rvalue is incorrect?  (    )

A.  User can write to lvalue reference

B. const lvalue is immutable constant to the user

C. rvalue reference is that the user can move the object referred to assuming it will never be used again.

D. lvalue and rvalue reference exist in C++ 98



14.  [Multiple choice] Which of following definitions and assignments are correct? (   )

A.  const int a = 10;

B.  const int a = 10;

auto &b = a;

C.  int a = 10;

int &b =a;

D.  const int a = 10;

     const auto b = a;

     b = 20;

15. [Multiple choice] What kind of constructor or operator are used below? (  )

class Someclass

{

public:

Someclass(const Someclass &) = default;

   Someclass & operator=(const Someclass &) = default;

};

A. Copy constructor

B. Move constructor

C. Copy assignment operator

D. Move assignment operator



16.  Please select the proper lambda function to get the output 6? (    )

int a{5};

std::cout << f() << std::endl;


A. auto f = []{ return ++a;};

B. auto f = [a] {return ++a;};

C. auto f = [&] {return a;};

D. auto f = [=] () mutable {return ++a;};



17.  What is the output of the following program? (    )

int a{};

auto f = [=]{ return a+2;};

a += 1;

std::cout  << f() <<  std::endl;

A. 3

B. 2

C. 1

D. 0


18.  Which expression can not pass the compilation? (    )

A. int a = 2.2;

B. int b = {2.3};

C. std::vector<int> v{ 1, 2, 3, 4 };

D. std::array<double, 10> values {0.5, 1.0, 1.5, 2.0};



19.  Which vector function is used to reversal iteration? (    )

A. vec.begin()

B. vec.cbegin()

C. vec.rbegin()

D. vec.cend()



20.  Which description is right about variadic templates’ parameters? (    )

A. The numbers of parameters are restricted.

B. The types of parameters are restricted.

C. The numbers and types of parameters are unrestricted.

D. The numbers of parameters are unrestricted, but the types of parameters are restricted.



21.  Which one is right format to use a variadic templates? (    )

A. template<typename T, typename... TRest>

B. template< typename T, typename, TRest>

C. template<typedef T, typedef... TRest>  

D. template<typedef T, typedef, TRest>



22.  [Multiple choice] Which of the following objects can use constexpr? (    )

A. functions;

B. variables

C. pointers

D. references



23.  Related to sum calculation (don’t consider overflow), which of the following is true? (    )

A.

auto sum (int i)

{

 if (i != 1)

   return sum(i-1)+i;

 return i;

}

B.

auto sum (int i)

{

 if (i == 1)

return i;

  return sum(i-1)+i;

}




24.  About “alternate type deduction on declaration”, which of the following statements is wrong? (    )

int   i;

int&& f();

auto          x3a = i;

decltype(i)   x3d = i;

auto          x4a = (i);

decltype((i)) x4d = (i);

auto          x5a = f();

decltype(f()) x5d = f();

A. decltype(x3a) is int, decltype(x4a) is int, decltype(x5a) is int

B. decltype(x3d) is int&

C. decltype(x4d) is int&

D. decltype(x5d) is int&&



25.  Here is an example of “Variable templates”,

-----------------------------

template<typename T>

constexpr T pi = T(3.141592653589793238462643383);

// Usual specialization rules apply:

template<>

constexpr const char* pi<const char*> = "pi";

auto intPi = pi<int>; //3

auto lessPi = pi<float>; //3.14159274, lower precision

auto morePi = pi<double>; //3.1415926535897931, higher precision

auto strPi = pi<const char*>;//pi

-----------------------------

Which of the following statements is true? (    )

A. Since C++11, not only functions, classes or type aliases could be templated, but also allows the creation of variables that are templated.

B. Before C++14, only functions, classes or type aliases could be templated. C++14 now allows the creation of variables that are templated.



[Bonus question]


This question is about the using of std::function, std::bind, lambda, please fill in the blanks.


#include <iosteam>

#include <functional>


class Foo {

public:

   void printSum(const int &n1, const int &n2)

   {

       std::cout << n1+n2 << std::endl;

   }

};

double myDivide(const double &x, const double &y)

{

return x/y;

}


int main ()

{

// std::function + std::bind member function    

// implement add by 5, using printSum of class Foo.

Foo foo;

std::function<Q1> add = std::bind(Q2, Q3, 5, std::placeholders::_1);

add(5);


// std::function + std::bind normal function

// implement divide by 2, using the function myDivide.

auto half = std::bind (Q4,Q5, 2);  

std::cout << half(10) << std::endl;


// lambda expression

int a{};

auto f = [&]{ return a+2;};

a += 1;

std::cout  << f() <<  std::endl;//output will be Q6


return 0;

}


Please write down the answers to questions of Q1 ~ Q6 in the below:


Q1:


Q2:


Q3:


Q4:


Q5:


Q6:


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp