c语言中将函数指针作为形参_在C中将有效指针作为NULL指针
c語言中將函數(shù)指針作為形參
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,可以將包含有效內(nèi)存地址的任何指針設(shè)置為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指針,此后,我們?yōu)閜tr分配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語言中將函數(shù)指針作為形參
總結(jié)
以上是生活随笔為你收集整理的c语言中将函数指针作为形参_在C中将有效指针作为NULL指针的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 颐和园可以骑滑板车吗
- 下一篇: “清跸戒驰路”下一句是什么