PRF192 - Cơ sở lập trình
Câu hỏi của môn
#include <stdio.h>
void swap(int *px, int *py)
{
int z;
z=*px;
*px=*py ;
*py=z ;
}
int main()
{
int a=15, b=21 ;
swap(&a,&b);
printf ("%d %d",a,b);
return 0;
}#include <stdio.h>
double average(int a, int b, int c) {
double result;
result = (a+b+c)/3.0;
return result;
}
int main() {
printf("%.6f", average(5, 8, 7));
return 0;
}int a[MAX_SIZE];
int s = 0;
for (int i = 0; i < n; i++)
s = s + a[i] * a[i];pointersvaluetypeaddressint a[5] = {1, 2, 3};
printf("%d", a[4]);void main()
{
int const *p = 5;
printf("%d", ++(*p));
getchar();
}char str1[] = "Hello";
char str2[10];
strcpy(str2, str1);Đáp án đúng: "Throughout the entire program". Biến khai báo ngoài mọi hàm có phạm vi tệp và thời gian sống tĩnh: nó được cấp chỗ một lần khi chương trình nạp và tồn tại tới lúc kết thúc, nên mọi hàm viết sau khai báo đều thấy nó, và tệp nguồn khác cũng dùng được qua khai báo extern; đó chính là nghĩa của cả chương trình. Mô tả "Only within the function where it's declared" ứng với biến cục bộ, thứ sinh ra trên khung ngăn xếp mỗi lần gọi hàm rồi mất đi khi hàm trả về. Mô tả "Only within the block where it's declared" là phạm vi khối, áp cho biến khai báo trong cặp ngoặc nhọn của thân vòng lặp hay nhánh rẽ. Mô tả "Within the structure where it's defined" nhầm biến với trường của struct; trường chỉ là thành phần của một kiểu, chạm tới qua tên biến struct chứ không phải một biến toàn cục.
#include <stdio.h>
int main() {
int quantity;
double cost;
printf("Enter the number of apples desired: ");
scanf("%d", &quantity);
printf("Now enter the cost of one apple (in $): ");
scanf("%lf", &cost);
printf("That will cost $%.2lf\n", quantity * cost);
return 0;
}#include <stdio.h>
int main() {
int arr[] = {5, 10, 15};
for (int i = 0; i < 3; i++)
printf("%d ", arr[i]);
return 0;
}char s[] = "AbCd";
printf("%d;%d;%d;%d", s[1], s[2], s[3], s[4]);#include <stdio.h>
int main()
{
int x = 5, y = 3, z = 1;
x = x % 3 + z++;
z = x * y--;
printf("%d %d %d", x, y, z);
return 0;
}