您的位置:首页 > 编程语言 > C语言/C++

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用法规范;

这个能牵扯出很多的问题;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: