Ask Question

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;

}

+5
Answers (1)
  1. Today, 12:15
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers