Embedded C/C++ Specialized Test Questions

1. In linux+gcc, which of the following statements about the code is incorrect?____.

std::string& test_str()

{

std::string str=”test”;

return str;

}

int main()

{

std::string& str_ref=test_str();

std::cout<<str_ref<<std::endl;< p=”” style=”margin-right: auto; margin-left: auto;”></str_ref<<std::endl;<>

return 0;

}

A Compilation warning

B Returns a reference to a local variable, runtime unknown error

C Compiles and runs normally

D After removing all & from the code, the program can run normally

2. Assuming the definition of a two-dimensional array is “int a[3][4]={{3,4},{2,8,6}};”, what is the value of element a[2][1]?____.

A 0

B 4

C 8

D 6

3. Which of the following is the correct syntax for the template of sort?

A void sort(class A first, class A last, class B pred)

B void template(class A, class B)sort(A first, A last, B pred)

C template void sort(A first, A last, B pred)

D template void sort(A first, A last, B pred)

4. Which of the following statements is correct?

A Any existing operator in C++ can be overloaded

B const objects can only call const member functions

C Both constructors and destructors can be virtual functions

D Function overloading must have the same return type

5. For the following function call:

? fun(a+b,?3,?max(n-1,?b));? The number of actual parameters is____.

A 3

B 4

C 5

D 6

6. When two equivalent threads concurrently execute the following program, where a is a global variable initialized to 0, assuming printf, ++, and — operations are atomic, which output is definitely not possible?

void foo() {

if(a <= 0) {

a++;

}

else {

a–;

}

printf(“%d”, a);

}

A 01

B 10

C 12

D 22

7. In a 32-bit operating system with gcc compiler environment, what is the output of the following program?____.

#include

using namespace std;

class A {

public:

int b;

char c;

virtual void print() {

cout << “this is father’s function! ” << endl;

}

};

class B: A {

public:

virtual void print() {

cout << “this is children’s function! ” << endl;

}

};

int main(int argc, char * argv[]) {

cout << sizeof(A) << “” << sizeof(B) << endl;

return 0;

}

A 8 8

B 9 9

C 12 12

D 12 16

8. What is the difference between overloading and overriding?

A Overloading: allows multiple functions with the same name but different parameter lists

B Overloading: refers to the subclass redefining the method of a virtual function

C Overriding: refers to the subclass redefining the method of a virtual function

D Overriding: allows multiple functions with the same name but different parameter lists

Reference answers: 1~8: C A D B A A C AC

Regularly share embedded knowledge in an easy-to-understand way,follow the public account, add a star, and improve a little every day.

Disclaimer:

The original articles, images, etc. published by this account are owned by the original author. If there is any infringement, please contact to delete.

Embedded C/C++ Specialized Test QuestionsFollow, like, read, share, and support quality content!Embedded C/C++ Specialized Test Questions

Leave a Comment