c中的NULL 0 '\0'的一些问题

在c语言中字符串结尾为'\0',  这是字符格式,

char *p = '\0' ;   读出来(使用priintf输出)的就是空

也可以char *p = 0;  这个是直接等于ascii码格式,

char *p = 97,   printf("%c", *p)   就是a

区别char *p = ' 0 ';   -->等价于char *p = 48;

字符'0' 的ascii值就是48。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[])
{
    printf("%d\n", '\0');
    printf("%d\n", NULL);
    printf("%c\n", '0');
    char p = 97;
    printf("%c\n", p);//ascii转化成字符
    return 0;
}

NULL:

#if !defined(NULL)&&defined(__NEEDS_NULL)
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
在C和C++中的NULL是不同的

  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值