Skip to content
Question of 97

Q.Write definition for a function XOXO(char M[4][4]) in C++, which replaces every occurrence of an X with an O in the array, and vice versa. For example : ORIGINAL ARRAY M X X O X O X O O X O X X X X O O CHANGED ARRAY M O O X O X O X X O X O O O O X X NOTE : DO NOT DISPLAY the Changed Array contents. Do not use any other array to transfer the contents of array M.

(OR)
Write definition for a function ColSwap(int A[4][4]) in C++, which swaps the contents of the first column with the contents of the third column. For example : ORIGINAL ARRAY A 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 CHANGED ARRAY A 20 15 10 25 40 35 30 45 60 55 50 65 80 75 70 85 NOTE : DO NOT DISPLAY the Changed Array contents. Do not use any other array to transfer the contents of array A.
CBSECBSE Class XII Board 2019Subjective· 2mImportance★★★★★
0% · 0/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a) interchanges every X with O (and vice versa) in a 4×4 char array in place; Part (b) swaps the first column with the third column of a 4×4 int array in place — neither uses a second array.

Part (a)

Visit each cell; if it holds 'X' set it to 'O', and only otherwise if it holds 'O' set it to 'X'. Using else if prevents flipping a just-changed cell back.

void XOXO(char M[4][4]) {
    for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++) {
            if (M[i][j] == 'X')
                M[i][j] = 'O';
            else if (M[i][j] == 'O')
                M[i][j] = 'X';
        }
}
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.