Thursday, February 2, 2012

C/C++ Exercise: array and pointer

#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: array and pointer" << endl << endl;

 const int SIZE = 5;
 int number[SIZE] = {0, 1, 2, 3, 4};

 cout << "address of &number[i] - " << endl;
 for(int i = 0; i < SIZE; i++ ){
  cout << &number[i] << ":";
 }
 cout << endl;

 cout << "accessed using pointer - " << endl;
 int *pnumber = &number[0];
 for(int i = 0; i < SIZE; i++ ){
  cout << pnumber++ << ":";
 }
 cout << endl;
 
 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: array and pointer

No comments:

Post a Comment