100+ câu trắc nghiệm Lập trình nâng cao có đáp án phần 3

Anh (Chị) hãy cho biết kết quả của đoạn lệnh sau là gì?1. class CVector {2. public :3. int x,y;4. CVector () {}5. CVector (int,int);6. CVector operator+ (CVector);7. };8. CVector::CVector (i

23/25

Anh (Chị) hãy cho biết kết quả của đoạn lệnh sau là gì?

1. class CVector {

2. public :

3. int x,y;

4. CVector () {}

5. CVector (int,int);

6. CVector operator+ (CVector);

7. };

8. CVector::CVector (int a,int b) {

9. x = a;

10. y = b;

11. }

12. CVector CVector::operator+ (CVector v) {

13. CVector tmp;

14. tmp.x = x + v.x;

15. tmp.y = y + v.y;

16. return tmp;

17.}

18 .int main () {

19. CVector a (3,1);

20. CVector b(8,4);

21. CVector c;

22. c = a + b;

23. cout << c.x + c.y << endl;

24. return 0;

25.}

-8

5

16

4

Giải thích

Chọn đáp án C