int k= "hello";
printf("%s", k);
为什么即使 k 的数据类型是整数,也会打印出这个 hello?
最佳答案
您的代码调用Undefined Behavior .
int k= "hello";
您正在尝试使用字符串文字(char*
)初始化int
。这没有任何意义并调用 UB .
printf("%s", k);
您正在尝试使用 %s
打印 int
,它需要 char*
。这也没有意义并调用 UB .
关于c - 为什么存储在整数中的字符串会被打印出来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535842/