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

21 lines
503 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
请找出程序的错误行数(
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);
}