next up previous
Next: Beispiel: Bubblesort Up: Pointer-Arithmetik Previous: Pointer - Pointer

Zweidimensionale Arrays

#include <iostream.h>
extern "C" { 
  #include <stdlib.h>
}
const int ROWS=2;
const int COLS=4;

main(int argc, char **argv)
{
  int a[][COLS]  = { {0,1,2,3}, {4,5,6,7} };
    // die Spaltengröße muß explizit angegeben werden!
  int *p = &a[0][0], i, j; 

  if (argc != 3)
  { cerr << "Usage: " << argv[0] 
      << " number1 number2" << endl;
    exit(1);
  }
  i = atoi(argv[1]); j = atoi(argv[2]);        
  cout << "i=" << i << " j=" << j 
    << " a[i][j]=" << *(p + i * COLS + j) << endl; 

  cout << "i=" << i << " j=" << j 
    << " a[i][j]=" << a[i][j] << endl; 
}


next up previous
Next: Beispiel: Bubblesort Up: Pointer-Arithmetik Previous: Pointer - Pointer

© 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 3/19/1998