1 sizeof一个指针是多少
既然指针只是要存储另一个变量的地址,。注意,是存放一变量的地址,而不是存放一个变量本身,所以,不管指针指向什么类型的变量,它的大小总是固定的:只要能放得下一个地址就行!(这是一间只有烟盒大小的“房间”,因为它只需要入一张与着地址的纸条)。
存放一个地址需要几个字节?答案是和一个 int 类型的大小相同:4字节。
str1是一个指针 输出为1
*str1是一个字符
str2是一个字符串 但是记住加上 的长度
*str2是第一个字符
str3是整个的字符串 是预先分配的长度
2 static的用途
http://www.cnblogs.com/dc10101/archive/2007/08/22/865556.html
const的用途
http://www.cppblog.com/xczhang/archive/2008/01/13/41092.html
3 进程和线程的区别
http://www.cnblogs.com/lmule/archive/2010/08/18/1802774.html
4 c++内存分配的几种方式
http://www.cnblogs.com/daocaoren/archive/2011/06/29/2092957.html
5 max宏 得到两个数的最大值
http://blog.csdn.net/jk110333/article/details/8021231
6 野指针
http://www.cnblogs.com/evisie/archive/2011/08/04/2128051.html
这里再补充几个
#include <stdio.h> void GetMemory(char *p) { p = (char*) malloc(100); } void Test(void) { char *str = NULL; GetMemory(str); strcpy(str, "helloworld"); printf(str); } int main() { Test(); return 0; }
这一个是没办法成功运行的,str没有获取到分配的内存地址
#include <stdio.h> char *GetMemory(void) { char p[] = "helloworld"; return p; } void Test(void) { char *str = NULL; str = GetMemory(); printf(str); } int main() { Test(); return 0; }
变量的作用域的问题
#include <stdio.h> void GetMemory2(char **p, int num) { *p = (char*) malloc(num); } void Test(void) { char *str = NULL; GetMemory(&str, 100); strcpy(str, "hello"); printf(str); } int main() { Test(); return 0; }
没有free
7 strcmp函数的自己实现