chapter 3 截止到整数

This commit is contained in:
wandoubaba517 2023-12-02 19:27:07 +08:00
parent f0fb56c2c8
commit 0b8e953d4b
3 changed files with 42 additions and 4 deletions

25
c03_data/altnames.c Normal file
View File

@ -0,0 +1,25 @@
/* altnames.c - 可移植整数类型名 */
#include <stdio.h>
#include <inttypes.h> // 支持可移植类型
int main(void)
{
int32_t me32; // me32是一个32位有符号整型变量
me32 = 45933945;
printf("First, assume int32_t is int: ");
printf("me32 = %d\n", me32);
printf("Next, let's not make any assumptions.\n");
printf("Instead, use a \"macro\" from inttypes.h: ");
printf("me32 = %" PRId32 "\n", me32);
/*
PRId32 <inttypes.h>32int32_t
PRId32 32
使 %d int32_t
%d 1664 int32_t 32
使 PRId32 32
*/
return 0;
}

13
c03_data/charcode.c Normal file
View File

@ -0,0 +1,13 @@
/* charcode.c - 显示字符的代码编号 */
#include <stdio.h>
int main(void)
{
char ch;
printf("Please enter a character.\n");
scanf("%c", &ch);
printf("The code for %c is %d.\n", ch, ch);
return 0;
}

View File

@ -3,10 +3,10 @@
int main(void) int main(void)
{ {
printf("un = %ld and not %ld\n", 3000000000, 3000000000); printf("un = %u and not %d\n", 3000000000, 3000000000);
printf("end = %d and %d\n", 200, 200); printf("end = %hd and %d\n", 200, 200);
printf("big = %ld and not %d\n", 65537, 65537); printf("big = %ld and not %hd\n", 65537, 65537);
printf("verybig = %ld and not %ld\n", 12345678908642, 12345678908642); printf("verybig = %lld and not %d\n", 12345678908642, 12345678908642);
return 0; return 0;
} }