Table Of Contents
Previous Section Next Section

Program 29: It's Elementary, My Dear Reader

The following program is designed to print out a 3-by-3 matrix. But the results aren't the elements of the matrix; they are something else instead. What's going on?

  1 /************************************************
  2  * print_element --  Print an element in a      *
  3  *      matrix.                                 *
  4  ************************************************/
  5 #include <iostream>
  6
  7 // A simple matrix
  8 int matrix[3][3] = {
  9     {11, 12, 13},
 10     {21, 22, 23},
 11     {31, 32, 33}
 12 };
 13
 14 int main()
 15 {
 16     std::cout << "Element[1,2] is " <<
 17         matrix[1,2] << std::endl;
 18     return (0);
 19 }

(Next Hint 89. Answer 86.)

Table Of Contents
Previous Section Next Section