这里我们将看到一个程序。我们将尝试以读取模式打开系统中不存在的文件。所以该函数将返回空值。我们可以使用 if 语句来检查它。请参阅代码以更好地理解。
示例代码#include <stdio.h>main() { //try to open a file in read mode, which is not present file *fp; fp = fopen("hello.txt", "r"); if(fp == null) printf("file does not exists"); fclose(fp);}
输出file does not exists
以上就是如何在c/c++中检查变量是否为null?的详细内容。
