C++经常容易出错的问题,整理
2012-10-20 01:14
337 查看
首先推荐几本书:effective c++ 、thinking in C++ ,inside the C++ model .C专家编程
1,sizeof的用法,这个貌似老生常谈,但是还是有很多人每天都错;g
a ,基本用法比如问你sizeof(char*) sizeof(char) sizeof(void*) sizeof(void) sizeof(int) sizeof(long)。。。这些每个都需要注意
b,sizeof 对于数组和字符串之间的用法 char a[]="helloworld";
sizeof(a)是多少,strlen(a)之间差别有多大;
c,在函数中调用sizeof(array)用法;
这个很多人会犯错,其中错误最厉害的就是:sizeof(char*) sizeof(int *)sizeof(void*) ,三者都是4(32位机器);
其次就是sizeof(array(char))和strlen(array) 然后就是sizeof(int) sizeof(long);
2,数组和指针之间的区别是什么?
http://blog.sina.com.cn/s/blog_65a9944d0100v29b.html;
http://topic.csdn.net/u/20091123/11/0c03d2e2-0655-4634-8287-0e2315d889fc.html?52608
3, if else语句和switch之间的是什么关系?
本质上来说,这两者是不同的,不要自以为以为switch就是ifelse的转化版,或者怎么样
/article/10247808.html
4,map.containKey() 和map.containValue()复杂度各是多少?
如果这个闹不准,重新学习map
5,static在类中起到的作用是什么?const 和static在类中之间是很么关系?
共享数据、共享功能接口,隐蔽特性;static成员函数,static成员变量及初始化;
6,staitc全部变量和全局变量之间是什么关系?
隐藏特性、初始化特点、全局static和局部static重名冲突问题;
/article/9099449.html
7,关于类对象
class A{} sizeof(A)=?
class B:public A{} sizeof(B)=?
...此系列的判断
8.怎样正确使用if语句?
选自:高质量编程林博士:http://man.chinaunix.net/develop/c&c++/c/c.htm#_Toc520634014
9,if(NULL==p) 和 if(p==NULL)之间差别多大?
有人说,实践证明没多大效果,不纠结只因为规范性。但是对于程序的理解差别在此;
10,char * GetValue()
{
char *tem=new char[10];
memcpy(tem,"hello world",sizeof());
return tem;
}
int main()
{
char * p=GetValue();
cout<<p<<endl;
delete p;
return 0;
}
此程序会出现什么问题?
11, int * arrayNew=new int (length);
int * arrayNew=new int[length];之间差别;
分别在g++和vc上差别呢?
12,size_t & size_type的区别
使用场合、正确大小、表示含义、多类型运算类型转换等
string.h vector.h tchar.h cstdef.h string::size_type vector<int>size_type
/article/9099461.html
13,_T()了解多少?
/article/9099460.html
14,typedef 用法细节?
/article/9099453.html
15,const用法
/article/9099452.html
16.类初始化列表
17,位域详细
/article/9099448.html
18,类型转化符
const_cast <new_type> (expression)
static_cast <new_type> (expression)
reinterpret_cast <new_type> (expression)
dynamic_cast <new_type> (expression)
/article/9099454.html
19,new delete用法规范;
这个能牵扯出很多的问题;
1,sizeof的用法,这个貌似老生常谈,但是还是有很多人每天都错;g
a ,基本用法比如问你sizeof(char*) sizeof(char) sizeof(void*) sizeof(void) sizeof(int) sizeof(long)。。。这些每个都需要注意
b,sizeof 对于数组和字符串之间的用法 char a[]="helloworld";
sizeof(a)是多少,strlen(a)之间差别有多大;
c,在函数中调用sizeof(array)用法;
这个很多人会犯错,其中错误最厉害的就是:sizeof(char*) sizeof(int *)sizeof(void*) ,三者都是4(32位机器);
其次就是sizeof(array(char))和strlen(array) 然后就是sizeof(int) sizeof(long);
2,数组和指针之间的区别是什么?
http://blog.sina.com.cn/s/blog_65a9944d0100v29b.html;
http://topic.csdn.net/u/20091123/11/0c03d2e2-0655-4634-8287-0e2315d889fc.html?52608
3, if else语句和switch之间的是什么关系?
本质上来说,这两者是不同的,不要自以为以为switch就是ifelse的转化版,或者怎么样
/article/10247808.html
4,map.containKey() 和map.containValue()复杂度各是多少?
如果这个闹不准,重新学习map
5,static在类中起到的作用是什么?const 和static在类中之间是很么关系?
共享数据、共享功能接口,隐蔽特性;static成员函数,static成员变量及初始化;
6,staitc全部变量和全局变量之间是什么关系?
隐藏特性、初始化特点、全局static和局部static重名冲突问题;
/article/9099449.html
7,关于类对象
class A{} sizeof(A)=?
class B:public A{} sizeof(B)=?
...此系列的判断
8.怎样正确使用if语句?
选自:高质量编程林博士:http://man.chinaunix.net/develop/c&c++/c/c.htm#_Toc520634014
9,if(NULL==p) 和 if(p==NULL)之间差别多大?
有人说,实践证明没多大效果,不纠结只因为规范性。但是对于程序的理解差别在此;
10,char * GetValue()
{
char *tem=new char[10];
memcpy(tem,"hello world",sizeof());
return tem;
}
int main()
{
char * p=GetValue();
cout<<p<<endl;
delete p;
return 0;
}
此程序会出现什么问题?
11, int * arrayNew=new int (length);
int * arrayNew=new int[length];之间差别;
分别在g++和vc上差别呢?
12,size_t & size_type的区别
使用场合、正确大小、表示含义、多类型运算类型转换等
string.h vector.h tchar.h cstdef.h string::size_type vector<int>size_type
/article/9099461.html
13,_T()了解多少?
/article/9099460.html
14,typedef 用法细节?
/article/9099453.html
15,const用法
/article/9099452.html
16.类初始化列表
17,位域详细
/article/9099448.html
18,类型转化符
const_cast <new_type> (expression)
static_cast <new_type> (expression)
reinterpret_cast <new_type> (expression)
dynamic_cast <new_type> (expression)
/article/9099454.html
19,new delete用法规范;
这个能牵扯出很多的问题;
相关文章推荐
- C++链接几个经常出错的问题
- 整理一些C++面试容易被问到的问题及其答案
- 关于C++语法的一个容易出错的地方。
- 因为开发中遇到很多C++的问题,以后会经常来csdn寻求帮助了!
- Java中一些经常出错的问题
- 容易出错的指针问题
- 利用Struts 处理 web程序时 一些容易出错的问题
- C++中类设计中重要且容易忽视的问题
- [C / C++] undefined reference问题总结: 我在Google上目前找到最为全面并容易理解的
- Windows C++程序调用包含TensorFlow代码的Python脚本出错问题的解决办法
- C++ 经常容易忘记的概念
- c++ vector遍历删除元素 出错的问题
- C++程序员经常问的11个问题
- C++程序员经常问的11个问题
- 面试笔试整理2:c++常问问题
- C/C++容易迷惑问题(也属经典问题),共同学习……
- C++程序员经常问的11个问题
- Python新手在作用域方面经常容易碰到的问题
- C++面试常见问题整理(待补充)
- php数据库连接时容易出错的特殊符号问题