Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2013
Questions

Q51

MCQ2 marks, −0.67Data structuresMedium

The procedure given below is required to find and replace certain characters inside an input character string supplied in array AA. The characters to be replaced are supplied in array oldcoldc, while their respective replacement characters are supplied in array newcnewc. Array AA has a fixed length of five characters, while arrays oldcoldc and newcnewc contain three characters each. However, the procedure is flawed.

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 procedure is tested with the following four test cases. (1) oldc=“abc”,newc=“dab”\text{oldc} = \text{“abc”}, \text{newc} = \text{“dab”} (2) oldc=“cde”,newc=“bcd”\text{oldc} = \text{“cde”}, \text{newc} = \text{“bcd”} (3) oldc=“bca”,newc=“cda”\text{oldc} = \text{“bca”}, \text{newc} = \text{“cda”} (4) oldc=“abc”,newc=“bac”\text{oldc} = \text{“abc”}, \text{newc} = \text{“bac”} If array AA is made to hold the string “abcdeabcde”, which of the above four test cases will be successful in exposing the flaw in this procedure?

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.