Ask Question
8 November, 12:08

Apakah ada yang bisa menjelaskan potongan source code ini?

string fuse (char kata1[100], char kata2[100]) {

char jawaban[100];

int ssr, j=0;

if (strlen (kata1) >=strlen (kata2)) {

ssr = strlen (kata1);

}else{ssr = strlen (kata2); };

for (int i=0; i if (kata1[i]!='/0') {

jawaban[j]=kata1[i];

}else{

jawaban[i]=' ';

}

j++;

if (kata2[i]!='/0') {

jawaban[j]=kata2[i];

}else{

jawaban[j]=' ';

}

j++;

}

jawaban[j]='/0';

return jawaban;

}

+3
Answers (1)
  1. 8 November, 15:46
    0
    This code attempts to fuse two strings together. So,

    fuse ("Apple", "Banana")

    would return "ABpapnlaen a"

    However, there are a couple of things wrong with this code:

    - The for loop is incomplete (probably a copy paste error)

    - It is unclear from the code if the array jawaban will overflow if kata1 and kata2 are large (it probably will)

    - Biggest problem: the jawaban array is declared on the stack, which means it will be cleaned up when the function returns. So the caller of this function will reference unallocated memory! This is a huge bug!
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Apakah ada yang bisa menjelaskan potongan source code ini? string fuse (char kata1[100], char kata2[100]) { char jawaban[100]; int ssr, ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers