Concatenating strings in C, which method is more efficient?

后端 未结 10 929
迷失自我
迷失自我 2020-11-28 19:51

I came across these two methods to concatenate strings:

Common part:

char* first= \"First\";
char* second = \"Second\";
char* both = malloc(strlen(fi         


        
10条回答
  •  萌比男神i
    2020-11-28 20:41

    I don't know that in case two there's any real concatenation done. Printing them back to back doesn't constitute concatenation.

    Tell me though, which would be faster:

    1) a) copy string A to new buffer b) copy string B to buffer c) copy buffer to output buffer

    or

    1)copy string A to output buffer b) copy string b to output buffer

提交回复
热议问题