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是不同的

  


發佈了73 篇原創文章 · 獲贊 18 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章