問題 C 字串合併 指標與函式)

2021-09-12 20:31:12 字數 794 閱讀 4040

時間限制: 1 sec  記憶體限制: 128 mb

提交: 219  解決: 151

[提交][狀態][討論版]

定義乙個函式char *stradd(char *s1, char *s2),其返回的是s1和s2兩個字串合併後的值。(要求不能改變s1和s2)

測試資料的組數 t

第一組字串1

第一組字串2

第二組字串1

第二組字串2

第一組字串1 第一組字串2 第一組字串1和字串2的合併

第二組字串1 第二組字串2 第二組字串1和字串2的合併

hello world

string concatation

hello world helloworld

string concatation stringconcatation

#include #include using namespace std;

char *start;

char *p=new char[100];

char *stradd(char *s1,char *s2)

while (*s2!='\0')

while (*p1!='\0')

cout<<" ";

while (*p2!='\0')

cout<<" ";

return start;//不能使用區域性空間

}int main()

cout<}

return 0;

}

C 字串指標與字串陣列

在做面試100題中第21題時,發現char astr abcdefghijk 0 和char astr 有點區別,以前一直以為是一樣的,但是在該程式中採用字串指標執行一直出錯。後來在網上查查,果然發現大大的不同。分析 當你需要修改字串時,採用指標指向該字串編譯通過但是執行出錯,而採用字串陣列時不會出...

指標與陣列,指標與函式,指標與字串

首先我想解釋清楚指標與陣列名的關係,由下面的 引入問題,不知道大家有沒有好奇過為什麼它們三個是一樣的?include int main int argc,char argv printf p p p n a,a,a 0 return 0 那我們在看下面 答案顯而易見,就是a和 a 0 是一樣的,但是...

指標與陣列,指標與函式,指標與字串

指標與陣列,指標與函式,指標與字串 一 指標與陣列 首先我想解釋清楚指標與陣列名的關係,由下面的 引入問題,不知道大家有沒有好奇過為什麼它們三個是一樣的?include int main int argc,char argv printf p p p n a,a,a 0 return 0 1 234...