?
This document uses PHP Chinese website manual Release
在頭文件<stddef.h>中定義 | ||
---|---|---|
在頭文件<string.h>中定義 | ||
在頭文件<wchar.h>中定義 | ||
在頭文件<time.h>中定義 | ||
在頭文件<locale.h>中定義 | ||
在頭文件<stdio.h>中定義 | ||
在頭文件<stdlib.h>中定義 | ||
#define NULL / *實(shí)現(xiàn)定義* / |
宏NULL是一個(gè)實(shí)現(xiàn)定義的空指針常量,可能是這樣的。
一個(gè)整數(shù)常量表達(dá)式,值為0
值為0的整型常量表達(dá)式轉(zhuǎn)換為類型void *
空指針常量可以轉(zhuǎn)換為任何指針類型; 這種轉(zhuǎn)換會(huì)導(dǎo)致該類型的空指針值。
| // C ++ compatible:#define NULL 0 // C ++不兼容:#define NULL(10 * 2 - 20)#define NULL((void *)0)|
|:----|
#include <stdlib.h>#include <stdio.h>int main(void){ // any kind of pointer can be set to NULL int* p = NULL; struct S *s = NULL; void(*f)(int, double) = NULL; // many pointer-returning functions use null pointers to indicate error char *ptr = malloc(10); if (ptr == NULL) printf("Out of memory"); free(ptr);}
可能的輸出:
(none)
| 用于NULL的C ++文檔 |