#include <iostream> #include <conio.h> using std::cin; using std::cout; using std::endl; int main(){ cout << "http://dev-microsoft.blogspot.com/" << endl; cout << "Exercise: Access two-dimension array using pointer" << endl << endl; const int size_i = 3; const int size_j = 4; int a[size_i][size_j]; //init array for(int i = 0; i < size_i; i++){ for(int j = 0; j < size_j; j++){ a[i][j] = i * 10 + j; } } cout << endl; cout << "Accessed as two dimension array" << endl; for(int i = 0; i < size_i; i++){ for(int j = 0; j < size_j; j++){ cout << a[i][j] << " "; } cout << endl; } cout << endl; int *p = *a; cout << "Accessed by pointer" << endl; for(int i = 0; i < size_i * size_j; i++){ cout << i << ":" << *(p + i) << " "; } cout << endl; cout << endl; system("PAUSE"); return 0; }
Sunday, January 29, 2012
C/C++ Exercise: Access two-dimension array by pointer
Labels:
fundamental.C/Cpp
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment