c语言中将函数指针作为形参
Prerequisite:An Example of Null pointer in C
先决条件:C中的空指针示例
Any pointer that contains a valid memory address can be made as aNULL pointerby assigning0.
通过分配0,可以将包含有效内存地址的任何指针设置为NULL指针。
Example:
例:
Here, firstly ptr is initialized by the address of num, so it is not a NULL pointer, after that, we are assigning0to the ptr, and then it will become a NULL pointer.
在这里,首先ptr由num的地址初始化,因此它不是NULL指针,此后,我们为ptr分配0,然后它将成为NULL指针。
Program:
程序:
#include <stdio.h>int main(void) {int num = 10;int *ptr = #//we can also check with 0 instesd of NULL if(ptr == NULL)printf("ptr: NULL\n");elseprintf("ptr: NOT NULL\n");//assigning 0 ptr = 0;if(ptr == NULL)printf("ptr: NULL\n");elseprintf("ptr: NOT NULL\n");return 0;}
Output
输出量
ptr: NOT NULLptr: NULL
翻译自: /c-programs/making-a-valid-pointer-as-null-pointer-in-c.aspx
c语言中将函数指针作为形参