NULL
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <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)
|
例
Run this code
#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);
}
関連項目
NULL の C++リファレンス
|