龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

C和C++语言学习总结(一)

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
知识结构: 1、if,for,switch,goto 2、#define,const 3、文件拷贝的代码,动态生成内存,复合表达式,strcpy,memcpy,sizeof 4、函数参数传递,内存分配方式,内存错误表现,malloc与new区别 5、类重载、隐藏与

  知识结构:

  1、if,for,switch,goto

  2、#define,const

  3、文件拷贝的代码,动态生成内存,复合表达式,strcpy,memcpy,sizeof

  4、函数参数传递,内存分配方式,内存错误表现,malloc与new区别

  5、类重载、隐藏与覆盖区别,extern问题,函数参数的缺省值问题,宏代码与内联函数区别

  6、构造和析构的次序,String函数定义

  具体实现:

  1、if,for,switch,goto

if:

bool int float pointer char 变量的使用方法

bool bParam;

int iParam;

float fParam;

int* pParam;

char cParam;

if(bParam) ,if(!bParam);

if(iParam == 0 ),if(iParam != 0 );

if(fParam>= -0.00001 && fParam <= 0.00001);

if(pParam == NULL),if(pParam != NULL);

if(cParam == '),if(cParam != ');

if/else/return 的使用方法

if(condition) 可以等价为 return (condition?x:y);

{

return x;

}

else

{

return y;

}

for:

  执行效率问题:

int row,col,sum;

int a[100][5];

for(row=0;row <100;row++) 效率低于 for(col=0;col <5;col++)

{ {

for(col=0;col <5;col++) for(row=0;row <100;row++)

{ {

sum = sum+a[row][col]; sum = sum+a[row][col];

} }

} }

int i;

for(i=0;i

{ {

if(condition) for(i=0;i

DoSomething(); DoSomething();

else }

DoOtherthing(); else

} {

for(i=0;i

DoOtherthing();

}

for (int x=0;x <=N-1;x++) 直观性差于 for (int x=0;x

switch:

switch(variable)

{

case value1: ...

break;

case value2: ...

break;

default: ...

break;

}

精彩图集

赞助商链接