
C/C++ 面试
embeddedman
华东交大研究生
展开
-
const用法
1、const修饰的是变量,而不是常量,只是被修饰后的变量成为了“只读变量”; 如 const int Max = 100; int array[Max]; 这种定义在C语言编译会产生错误,而在C++扩展了const的含义,可以使用C++的作用域规则将其定义限定在特定的函数或文件中(作用域描述了名称在各种模块中的可知程度)。2、#原创 2012-05-15 15:42:19 · 1501 阅读 · 0 评论 -
内存思考
void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str = NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行Test函数会有什么样的结果?答:程序崩溃。因为GetMe原创 2012-05-16 10:43:22 · 1541 阅读 · 0 评论 -
面试系列指针与数组
#include int main(void){ char *p = "abcd"; p[1] = 'w'; printf(p); return 0;}编译通过,但是运行时会出现段错误#include int main(void){ char str[] = "abcd"; str[1] = 'w'; printf(s原创 2012-05-16 19:17:52 · 509 阅读 · 0 评论