Understanding NULL pointer in C

2019-06-24 00:06发布

I have found in some code NULL pointer is defined as follows -

#define NULL ((char *)0)

I found these code compiles fine. But I did not understand how this works. Can anyone please explain how 0 is casted to a char pointer?

And is it valid to use it as a FILE pointer making null -

FILE *fp = NULL;

标签: c pointers null
1条回答
不美不萌又怎样
2楼-- · 2019-06-24 00:24

The C library Macro NULL is the value of a null pointer constant.It may be defined as ((void*)0), 0 or 0L depending on the compiler vendor. Depending on compiler,declaration of NULL can be

#define NULL ((char *)0)

or

#define NULL 0L

or

#define NULL 0

And is it valid to use it as a FILE pointer making null--> Yes.

查看更多
登录 后发表回答