当前位置:
首页 >
c语言中将函数指针作为形参_在C中将有效指针作为NULL指针
发布时间:2023/12/1
44
豆豆
生活随笔
收集整理的这篇文章主要介绍了
c语言中将函数指针作为形参_在C中将有效指针作为NULL指针
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
c语言中将函数指针作为形参
Prerequisite: An Example of Null pointer in C
先决条件: C中的空指针示例
Any pointer that contains a valid memory address can be made as a NULL pointer by assigning 0.
通过分配0,可以将包含有效内存地址的任何指针设置为NULL指针 。
Example:
例:
Here, firstly ptr is initialized by the address of num, so it is not a NULL pointer, after that, we are assigning 0 to 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 NULL ptr: NULL翻译自: https://www.includehelp.com/c-programs/making-a-valid-pointer-as-null-pointer-in-c.aspx
c语言中将函数指针作为形参
总结
以上是生活随笔为你收集整理的c语言中将函数指针作为形参_在C中将有效指针作为NULL指针的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 颐和园可以骑滑板车吗
- 下一篇: 给定条件找最小值c语言程序_根据给定条件