C語(yǔ)言試題大全三
輸出到file2.txt:
(逆序)
答案:
注意可增長(zhǎng)數(shù)組的應(yīng)用.
#include
#include
int main(void)
{
int MAX = 10;
int *a = (int *)malloc(MAX * sizeof(int));
int *b;
FILE *fp1;
FILE *fp2;
{
}
for(;--j >= 0;)
fprintf(fp2,"%d",a[j]);
fclose(fp1);
fclose(fp2);
fclose(fp2);
free(a);
return 0;
}
}
2. 分析下面的代碼:
char *a = "hello";
char *b = "hello";
if(a= =b)
printf("YES");
else
printf("NO");
"hello"是一個(gè)常量字符串。位于靜態(tài)存儲(chǔ)區(qū),它在程序生命期內(nèi)恒定不變。如果編譯器優(yōu)化的話,會(huì)有可能a和b同時(shí)指向同一個(gè)hello的。則地址相同。如果編譯器沒(méi)有優(yōu)化,那么就是兩個(gè)不同的地址,則不同
char *a = "hello";
char *b = "hello";
if(a= =b)
printf("YES");
else
printf("NO");
"hello"是一個(gè)常量字符串。位于靜態(tài)存儲(chǔ)區(qū),它在程序生命期內(nèi)恒定不變。如果編譯器優(yōu)化的話,會(huì)有可能a和b同時(shí)指向同一個(gè)hello的。則地址相同。如果編譯器沒(méi)有優(yōu)化,那么就是兩個(gè)不同的地址,則不同
3. 兩個(gè)字符串,s,t;把t字符串插入到s字符串的第i個(gè)位置前,s字符串有足夠的空間存放t字符串
答案:
void insert(char *s, const char *t, int i)
{
void insert(char *s, const char *t, int i)
{