c語言題庫(含答案)_第1頁
c語言題庫(含答案)_第2頁
c語言題庫(含答案)_第3頁
c語言題庫(含答案)_第4頁
c語言題庫(含答案)_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1.inti=10,j=10,k=3;k*=i+j;k最后的值是?voidFunc(charstr[100])printf("%d\n",sizeof(str));3.寫出sizeof(structname2)的結(jié)果structname2{intnum;structname1{intnum;6.(void*)ptr和(*(void**))ptr的結(jié)果是否相同?7.#defineDOUBLE(x)x+x,i=5*DOUBLE(5);i是多少?constinta;intconsta;constint*a;int*consta;intconst*consta;10.do14..h頭文件中的ifndef/define/endif的作用?a[0]=0;a[1]=1;a[2]=2;int*p,*q;q=&a[2];則a[q-p]=a[2]intfunc(floata)default:0returnb;intsum(inta)autointc=0;staticintb=3;b+=2;return(a+b+c);voidmain()inta=2;for(I=0;I<5;I++)printf("%d,",sum(a));voidg(int**);intmain()intline[10],i;int*p=line;for(i=0;i<10;i++)g(&p);for(i=0;i<10;i++)printf("%d\n",line[i]);return0;voidg(int**p)(**p)++;(*p)++;intmain()inta[5]={1,2,3,4,5};int*ptr=(int*)(&a+1);//解釋解釋1printf("%d,%d",*(a+1),*(ptr-1));charstr1[]="abc";charstr2[]="abc";constcharstr3[]="abc";constcharstr4[]="abc";constchar*str5="abc";constchar*str6="abc";char*str7="abc";char*str8="abc";printf("%d",str1==str2);//數(shù)組名就是printf("%d",str3==str4);printf("%d",str5==str6);printf("%d",str7==str8);char*constp;constchar*p;9.unsignedshortarray[]={1,2,3,4,5,6,7};inti=3;*(array+i)=?inti=1;intj=i++;if((i>j++)&&(i++==j))i+=j;1.#defineMin(a,b)((a)<=(b)?(a):(b))19.#include與#include"file.h"的區(qū)別?char*strcpy(char*strDest,constchar*strSrc);答:1.char*strcpy(char*strDest,constchar*strSrc)char*strDestCopy=strDest;if(strDest==NULL||strSrc==NULL)throw("invalidarguments");while((*strDestCopy++=*strSrc++)!='\0');returnstrDest;#include#include#defineN100char*judgeStrings(char*str);intmain()printf("%s\n",judgeStrings(a));return0;char*judgeStrings(char*str)if(str==NULL)throw"error:strisNULL";intlen=strlen(str);for(inti=0;i<=""p="">if(str[i]!=str[len-i-1])return"no";return"yes!";#include#defineN20voidgetReverseChar(char*str);intmain()printf("\n");return0;voidgetReverseChar(char*str)if(*str=='\0')getReverseChar(str+1);printf("%c",*str);#include#includeintmain()chara[]="ABCD1234efgh";char*p=a;intlen=strlen(a);for(inti=0;i<len/2;i++)chartemp=a[i];a[i]=a[len-i-1];a[len-i-1]=temp;printf("%s\n",a);return0;答:#include#include#defineN100intmain()chars[N]="HelloWorld";char*t="welcometoBeijing";intsLen=strlen(s);inttLen=strlen(t);scanf("%d",&pos);if(pos>sLen||pos<0)return0;for(inti=0;i<sLen-pos;i++)s[pos+tLen+i]=s[pos+i];for(inti=0;i<tLen;i++)s[pos+i]=t[i];s[sLen+tLen]='\0';printf("%s\n",s);return0;intstrcmp(constchar*str1,constchar*str2),不調(diào)用庫函數(shù),答:#include#include#defineN100intstrcmp(constchar*str1,constchar*str2);intmain()chart[N];printf("%d\n",strcmp1(s,t));return0;intstrcmp(constchar*str1,constchar*str2)intlen1=strlen(str1);intlen2=strlen(str2);intmaxLen=len1>len2?len1:len2;for(inti=0;i<maxLen;i++)if(str1[i]>str2[i])return1;elseif(str1[i]<str2[i])return-1;return0;#include"string.h"voidmain(void){char*src="hello,world";char*dest=NULL;dest=(char*)malloc(strlen(src));intlen=strlen(str);char*d=dest;char*s=src[len];while(len--!=0)d++=s--;printf("%s",dest);答:1.string.h用<>括起來。dest=(char*)malloc(strlen(src)+1);3.intlen=strlen(str);改為intlen=strlen(src);4.char*s=src[len];改為char*s=src[len-1];5.d++=s--;改為*d++=*s--;6.需要在printf("%s",dest);上面加上一行代碼:*d='\0';#includevoidfoo(intm,intn)printf("m=%d,n=%d\n",m,n);intmain()intb=3;foo(b+=3,++b);printf("b=%d\n",b);return0;intarr[]={6,7,8,9,10};int*ptr=arr;*(ptr++)+=123;printf("%d%d",*ptr,*(++ptr));voidtest2()charstring[10],str1[10];for(i=0;i<10;i++)str1[i]='a';strcpy(string,str1);for(i=0;i<9;i++)char*RetMemory(void)charp[]="hellowworld";returnp;voidTest(void)char*str=NULL;str=RetMemory();printf(str);voidGetMemory(char**p,intnum)*p=(char*)malloc(num);intmain()char*str=NULL;GetMemory(&str,100);strcpy(str,"hello");if(str!=NULL)strcpy(str,"world");printf("\nstris%s",str);故str肯定不會為NULL。接著調(diào)用strcpy()函數(shù)為str指向的空間賦strcpy(szstr,"0123456789");#include#includevoidgetmemory(char*p)p=(char*)malloc(100);strcpy(p,"helloworld");intmain()char*str=NULL;getmemory(str);printf("%s/n",str);return0;intmain()char*str=&astrcpy(str,"hello");printf(str);return0;"dcba"1、#include"string.h"2、main()4、char*src="hello,world";5、char*dest=NULL;6、intlen=strlen(src);7、dest=(char*)malloc(len);8、char*d=dest;9、char*s=src[len];10、while(len--!=0)11、d++=s--;12、printf("%s",dest);13、return0;#inlcudeintmain()cha

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論