1. 头文件 ifndef/define/endif的作用
反正头文件多次引用
2. 定义一个宏实现MAX,找出a,b中的最大值
#define MAX(a, b) ((a) > (b)?(a):(b))
3.1 某32位系统下, C++程序,请计算sizeof 的值
void main
{
char str[] = "xmgcc";
void *p = malloc(100);
char *p2 = "str";
int n = 10;
sizeof(str) = 6
sizeof(p) = 4
sizeof(n) = 4
sizeof(p2) = 4
}
void Foo(char str[100])
{
sizeof(str) = 4
}
}
3.2 某64位系统下, C++程序,请计算sizeof 的值
void main
{
char str[] = "xmgcc";
void *p = malloc(100);
char *p2 = "str";
int n = 10;
sizeof(str) = 6
sizeof(p) = 8
sizeof(n) = 4
sizeof(p2) = 8
}
void Foo(char str[100])
{
sizeof(str) = 8
}
4. #include <file.h>和#include "file.h"的区别
#include < file.h>在系统路径查找file.h
#include “file.h"在当前路径查找file.h
5. 打印输出内容,如果代码存在问题,将解释
void GetMemory(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test1()
{
char *str = NULL;
GetMemory(&str, 100