GATEverse Practice, past papers & mock tests
GATE 2013 · session-1
Programming & Data StructuresProgrammingmediumMCQ2 marks
The procedure below must find and replace characters in input array A. Characters to be replaced are in oldc, and their respective replacements are in newc. A has five characters; oldc and newc have three each. However, the procedure is flawed.
c
void find_and_replace (char *A, char *oldc, char *newc) {
    for (int i=0; i<5; i++)
        for (int j=0; j<3; j++)
            if (A[i] == oldc[j]) A[i] = newc[j];
}
The four test cases are: (1) oldc="abc", newc="dab" (2) oldc="cde", newc="bcd" (3) oldc="bca", newc="cda" (4) oldc="abc", newc="bac" If array A holds the string "abcde", which of the four test cases will be successful in exposing the flaw?
Save your progress

Related Programming & Data Structures PYQs