qfedu-c-level/day12/homework/h3.c

21 lines
503 B
C
Raw Normal View History

2023-07-22 10:37:20 +08:00
/*
int main()
{
int a='21';
const char *p = (char *) &a;
*p = 48;
printf("%s\n", p);
}
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int a = '21'; // 错误1: '21' 是字符常量,不是整型常量,应该写成 21
const char *p = (char *)&a;
*p = 48; // 错误2: *p 在上一行被 const 修饰为了只读变量,无法修改
printf("%s\n", p);
}