Question

A C function print_matrix(int rows, int cols, int matrix[rows][cols]) is designed to print a matrix. #include void print_matrix(int rows, int cols, int matrix[rows][cols]) {     for (int i = 0; i <= rows; i++) { // Potential bug here         for (int j = 0; j < cols; j++) {             printf("%d ", matrix[i][j]);         }         printf("\n");     } } If print_matrix(2, 3, my_matrix) is called for a 2x3 matrix (rows 0, 1; cols 0, 1, 2), what will be the most likely outcome?

A It will print the matrix correctly.
B It will print the matrix and then attempt to access memory out of bounds, potentially causing a segmentation fault.
C It will print only the first row.
D It will print only the first column.
E A compile-time error will occur due to incorrect loop bounds.
Practice Next

Hey! Ask a query

🎓
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
  • 200 Questions with Detailed Solutions
  • Section-wise Coverage (GA, English, Quant & Reasoning)