完成习题12

This commit is contained in:
Wang Boyang 2025-04-07 13:23:40 +08:00
parent 1e68d514e2
commit 594ccd3ff1
5 changed files with 69 additions and 0 deletions

1
ex12/Makefile Normal file
View File

@ -0,0 +1 @@
CFLAGS=-Wall -g

BIN
ex12/ex12 Executable file

Binary file not shown.

37
ex12/ex12.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
char full_name[] = {
'Z', 'e', 'd',
' ', 'A', '.', ' ',
'S', 'h', 'a', 'w'// , '\0'
};
int areas[] = {95, 12, 13, 14, 20};
char name[] = "Zed";
areas[1] = 100;
name[3] = 'Z';
full_name[11] = 'Z';
name[0] = areas[0];
// WARNING: On some systems you may have to change // the %ld in this code to a %u since it will use
// unsigned ints
printf("The size of an int: %ld\n", sizeof(int));
printf("The size of areas (int[]): %ld\n", sizeof(areas));
printf("The number of ints in areas: %ld\n", sizeof(areas) / sizeof(int));
printf("The first area is %d, the 2nd %d.\n", areas[10], areas[1]);
printf("The size of a char: %ld\n", sizeof(char));
printf("The size of name (char[]): %ld\n", sizeof(name));
printf("The number of chars: %ld\n", sizeof(name) / sizeof(char));
printf("The size of full_name (char[]): %ld\n", sizeof(full_name));
printf("The number of chars: %ld\n", sizeof(full_name) / sizeof(char));
printf("name=\"%s\" and full_name=\"%s\"\n", name, full_name);
return 0;
}

30
ex12/ex12_copy.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
int areas[] = {10, 12, 13, 14, 20};
char name[] = "Zed";
char full_name[] = {
'Z', 'e', 'd',
' ', 'A', '.', ' ',
'S', 'h', 'a', 'w', '\0'
};
// WARNING: On some systems you may have to change // the %ld in this code to a %u since it will use
// unsigned ints
printf("The size of an int: %ld\n", sizeof(int));
printf("The size of areas (int[]): %ld\n", sizeof(areas));
printf("The number of ints in areas: %ld\n", sizeof(areas) / sizeof(int));
printf("The first area is %d, the 2nd %d.\n", areas[0], areas[1]);
printf("The size of a char: %ld\n", sizeof(char));
printf("The size of name (char[]): %ld\n", sizeof(name));
printf("The number of chars: %ld\n", sizeof(name) / sizeof(char));
printf("The size of full_name (char[]): %ld\n", sizeof(full_name));
printf("The number of chars: %ld\n", sizeof(full_name) / sizeof(char));
printf("name=\"%s\" and full_name=\"%s\"\n", name, full_name);
return 0;
}

1
ex12/vedio Normal file
View File

@ -0,0 +1 @@
http://ewm.ptpress.com.cn:8085/preview?qrCode=qr2018001489&verified=true