一、请填写 BOOL , float, 指针变量 与“零值”比较的 if 语句。#include iostream using namespace std; int main() { //BOOL flag 与“零值”比较 //if ( flag ) //if ( !flag ) //float x 与“零值”比较 //const float EPSINON 0.00001; //if ((x -EPSINON) (x EPSINON) //char* p 与“零值”比较 //if (p NULL) //if (p ! NULL) return 0; }二、以下为 Windows NT 下的 32 位 C程序请计算 sizeof 的值#include iostream using namespace std; int main() { //char str[] “Hello”; //char* p str; //int n 10; //请计算 // sizeof(str) 6 //5个字符 1个结束符\0 6 // sizeof(p) 4 //指针变量占4个字节 // sizeof(n) 4 //整数变量占4个字节 // void Func(char str[100]) //{ // 请计算 // sizeof(str) 4 // 指针变量占4个字节 //} //void* p malloc(100); //请计算 // sizeof(p) 4 //指针变量占4个字节 return 0; }三、头文件中的 ifndef/define/endif 干什么用// 第一步定义唯一的宏名通常是 头文件名大写 下划线避免冲突 #ifndef STUDENT_H_ // 如果 STUDENT_H_ 未定义 #define STUDENT_H_ // 定义 STUDENT_H_ // 以下是头文件的核心内容 #include string // 嵌套的其他头文件 // 声明结构体 struct Student { int id; std::string name; int age; }; // 声明函数 void printStudent(const Student stu); #endif // 结束 STUDENT_H_ 的条件编译#include student.h // 第一次包含STUDENT_H_ 未定义 → 编译头文件内容 #include student.h // 第二次包含STUDENT_H_ 已定义 → 跳过内容无错误 #include iostream using namespace std; // 实现头文件声明的函数 void printStudent(const Student stu) { cout ID: stu.id , 姓名: stu.name , 年龄: stu.age endl; } int main() { Student stu {101, 张三, 20}; printStudent(stu); return 0; }四、#include 和 #include “filename.h” 有什么区别#include iostream // 找系统里的iostream写代码时必用的标准输入输出头文件 #include stdio.h // 找系统里的C语言标准输入输出头文件#include student.h // 先在当前项目文件夹找自己写的student.h找不到再去系统目录 #include utils.h // 同理优先找本地的工具类头文件五、在 C 程序中调用被 C 编译器编译后的函数为什么要加 extern “C”// calc.cC编译器编译 #include stdio.h int add(int a, int b) { return a b; }// main.cppC编译器编译 #include iostream // 不加extern CC会找_add_int_int但C编译的是_add链接报错 int add(int a, int b); int main() { std::cout add(1,2) std::endl; // 链接错误undefined reference to add(int, int) return 0; }// main.cpp正确写法 #include iostream // 告诉C按C规则找add函数 extern C { int add(int a, int b); } int main() { std::cout add(1,2) std::endl; // 输出3正常运行 return 0; }