尝试用%s输出空指针

尝试用%s输出空指针:

#include <stdio.h>
int main (void)
{
    printf("%s\n", NULL);
    return 0;
}

clang:

cuihao@cuihao-arch /tmp $ clang test.c
cuihao@cuihao-arch /tmp $ ./a.out
(null)

pathcc:

cuihao@cuihao-arch /tmp $ pathcc test.c 
cuihao@cuihao-arch /tmp $ ./a.out
(null)

gcc:

cuihao@cuihao-arch /tmp $ gcc test.c 
test.c: 在函数‘main’中:
test.c:5:5: 警告:对空指针指向内容的读操作(实参 2) [-Wformat]
test.c:5:5: 警告:格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘void *’ [-Wformat]
cuihao@cuihao-arch /tmp $ ./a.out
[1]    5428 segmentation fault  ./a.out

g++:

cuihao@cuihao-arch /tmp $ g++ test.c 
test.c: 在函数‘int main()’中:
test.c:5:24: 警告:格式 ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘long int’ [-Wformat]
cuihao@cuihao-arch /tmp $ ./a.out
(null)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值