名前空間
変種
操作

NULL

提供: cppreference.com
< c‎ | types
ヘッダ <stddef.h> で定義
ヘッダ <string.h> で定義
ヘッダ <wchar.h> で定義
ヘッダ <time.h> で定義
ヘッダ <locale.h> で定義
ヘッダ <stdio.h> で定義
ヘッダ <stdlib.h> で定義
#define NULL /*implementation-defined*/

マクロ NULL は処理系定義のヌルポインタ定数で、以下のいずれかです。

ヌルポインタ定数は任意のポインタ型に変換できます。 そのような変換の結果はその型のヌルポインタ値になります。

[編集]実装例

// C++ compatible:#define NULL 0// C++ incompatible:#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 NULLint* p = NULL;struct S *s = NULL;void(*f)(int, double)= NULL;   // many pointer-returning functions use null pointers to indicate errorchar*ptr =malloc(10);if(ptr == NULL)printf("Out of memory");free(ptr);}


[編集]関連項目

close