JavaScript is required

Kết quả của chương trình sau là gì
#include
void hoanvi(int * px, int * py) {
int z;
z = * px;
* px = * py;
* py = z;
};
void main() {
int a = 15, b = 21;
hoanvi(a, b);
printf(“ % d % d”, a, b);
};

A.
“15 21”
B.
“21 15”
C.
Báo lỗi khi thực hiện chương trình
D.
Kết quả khác
Trả lời:

Đáp án đúng: B


The C program attempts to swap the values of variables `a` and `b` using the `hoanvi` function. However, it passes the variables by value instead of by reference (using pointers). This means the `hoanvi` function only modifies copies of `a` and `b`, not the original variables in `main`. Consequently, the `printf` statement will print the original values of `a` and `b`, which are 15 and 21. Therefore the correct answer is A.

Tổng hợp 600+ câu hỏi trắc nghiệm lập trình C có đáp án đầy đủ nhằm giúp các bạn dễ dàng ôn tập lại toàn bộ các kiến thức.


50 câu hỏi 60 phút

Câu hỏi liên quan