C面试题(整理)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

tag:zzCSDNtag::PlatformBuilder|:ImageloadingwithImagingAPIC/C++1.C/C++strcpystrcpystrcpy102strcpy2102.1voidtest1(){charstring[10];char*str1=0123456789;strcpy(string,str1);}2voidtest2(){charstring[10],str1[10];inti;for(i=0;i10;i++){str1[i]='a';}strcpy(string,str1);}3voidtest3(char*str1){charstring[10];if(strlen(str1)=10){strcpy(string,str1);}}1str111’\0’string10strcpy2str13strcpy(string,str1)str1string7strcpy103if(strlen(str1)=10)if(strlen(str1)10)strlen’\0’1(1)’\0’(2)(3)strcpystrcpy102voidstrcpy(char*strDest,char*strSrc){while((*strDest++=*strSrc++)!=‘\0’);}4voidstrcpy(char*strDest,constchar*strSrc)//const2{while((*strDest++=*strSrc++)!=‘\0’);}7voidstrcpy(char*strDest,constchar*strSrc){//03assert((strDest!=NULL)&&(strSrc!=NULL));while((*strDest++=*strSrc++)!=‘\0’);}10//3char*strcpy(char*strDest,constchar*strSrc){assert((strDest!=NULL)&&(strSrc!=NULL));char*address=strDest;while((*strDest++=*strSrc++)!=‘\0’);returnaddress;}210strcpystrcpy(4)strlen'\0'strcpy10strlenintstrlen(constchar*str)//const{assert(strt!=NULL);//0intlen;while((*str++)!='\0'){len++;}returnlen;}4voidGetMemory(char*p){p=(char*)malloc(100);}voidTest(void){char*str=NULL;GetMemory(str);strcpy(str,helloworld);printf(str);}5char*GetMemory(void){charp[]=helloworld;returnp;}voidTest(void){char*str=NULL;str=GetMemory();printf(str);}6voidGetMemory(char**p,intnum){*p=(char*)malloc(num);}voidTest(void){char*str=NULL;GetMemory(&str,100);strcpy(str,hello);printf(str);}7voidTest(void){char*str=(char*)malloc(100);strcpy(str,hello);free(str);...//}4GetMemory(char*p)char*str=NULL;GetMemory(str);strNULL5charp[]=helloworld;returnp;p[]6GetMemory4GetMemoryGetMemory*p=(char*)malloc(num);if(*p==NULL){...//}76char*str=(char*)malloc(100);free(str)str“”str=NULL;6Testmalloc4750~60123swap(int*p1,int*p2){int*p;*p=*p1;*p1=*p2;*p2=*p;}swapp“”VC++DEBUG“AccessViolation”swap(int*p1,int*p2){intp;p=*p1;*p1=*p2;*p2=p;}3.1BOOLintfloat“”ifvarBOOLif(!var)intif(var==0)floatconstfloatEPSINON=0.00001;if((x=-EPSINON)&&(x=EPSINON)if(var==NULL)0“”BOOL0if(var==0)intif(!var)if(!var)if“”“”if(var)if(!var)“”if(shortintlong)if(var==0)0“”if(var==NULL)float“==”“=”“=”“=”if(x==0.0)02WindowsNT32C++sizeofvoidFunc(charstr[100]){sizeof(str)=?}void*p=malloc(100);sizeof(p)=?sizeof(str)=4sizeof(p)=4Func(charstr[100])1charstr[10];coutsizeof(str)endl;10strchar[10]2charstr[10];str++;//str3WindowsNT324sizeof(str)sizeof(p)43“”MINleast=MIN(*p++,b);#defineMIN(A,B)((A)=(B)?(A):(B))MIN(*p++,b)“”“”1“”#defineMIN(A,B)(A)=(B)?(A):(B)#defineMIN(A,B)(A=B?A:B)02#defineMIN(A,B)((A)=(B)?(A):(B))MIN(*p++,b)((*p++)=(b)?(*p++):(*p++))p++0#defineMIN(A,B)((A)=(B)?(A):(B));“;”04#ifndef__INCvxWorksh#define__INCvxWorksh#ifdef__cplusplusexternC{#endif/*...*/#ifdef__cplusplus}#endif#endif/*__INCvxWorksh*/#ifndef__INCvxWorksh#define__INCvxWorksh#endifC++CC++symbolCvoidfoo(intx,inty);Csymbol_fooC++_foo_int_int_foo_int_intC++CC++C++CexternCexternCC_fooCC++5charn“abcdefghi”n=2“hiabcdefgh”//pStr'\0'//stepsnvoidLoopMove(char*pStr,intsteps){//...}1voidLoopMove(char*pStr,intsteps){intn=strlen(pStr)-steps;chartmp[MAX_LEN];strcpy(tmp,pStr+n);strcpy(tmp+steps,pStr);*(tmp+strlen(pStr))='\0';strcpy(pStr,tmp);}2voidLoopMove(char*pStr,intsteps){intn=strlen(pStr)-steps;chartmp[MAX_LEN];memcpy(tmp,pStr+n,steps);memcpy(pStr+steps,pStr,n);memcpy(pStr,tmp,steps);}1strcpy2memcpy3memset6WAVWAVWAVWAVWAVE00H4CharRIFF04H4int3208H4CharWAVE0CH4Charfmt10H414H2int1616H2int1618H2int161CH4int3220H2int1622H224H4Chardata28H4int32WAVWAVEFORMATtypedefstructtagWaveFormat{charcRiffFlag[4];UIN32nFileLen;charcWaveFlag[4];charcFmtFlag[4];charcTransition[4];UIN16nFormatTag;UIN16nChannels;UIN16nSamplesPerSec;UIN32nAvgBytesperSec;UIN16nBlockAlign;UIN16nBitNumPerSample;charcDataFlag[4];UIN16nAudioLength;}WAVEFORMAT;WAVbufferWAVEFORMATwaveFormat;memcpy(&waveFormat,buffer,sizeof(WAVEFORMAT));waveFormatWAV6memcpymemset7StringStringclassString{public:String(constchar*str=NULL);//String(constString&other);//~String(void);//String&operate=(constString&other);//private:char*m_data;//};//String::String(constchar*str){if(str==NULL){m_data=newchar[1];//'\0'//m_dataNULL*m_data='\0';}else{intlength=strlen(str);m_data=newchar[length+1];//NULLstrcpy(m_data,str);}}//StringString::~String(void){delete[]m_data;//deletem_data;}//String::String(constString&other)//const{intlength=strlen(other.m_data);m_data=newchar[length+1];//m_dataNULLstrcpy(m_data,other.m_data);}//String&String::operate=(constString&other)//const{if(this==&other)//return*this;delete[]m_data;//intlength=strlen(other.m_data);m_data=newchar[length+1];//m_dataNULLstrcpy(m_data,other.m_data);return*this;//}StringC++60%m_dataC++EffectiveC++60%C++8staticconststaticn1staticauto2static3static4static5staticthisstaticconstn1constconst2constconstconst3const4const5const“”constclassAoperator*(constclassA&a1,constclassA&a2);operator*constclassAa,b,c;(a*b)=c;//a*b(a*b)=cstaticconst1~2staticconst4.1CBig_endian0Little_endian1intcheckCPU(){{unionw{inta;charb;}c;c.a=1;return(c.b==1);}}Little-endianBig-endianLittle-endianCPU

1 / 88
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功