Sunday, September 4, 2011

Pointer and Array

Pointer and Array



#include <iostream>


using namespace std;

int main()
{
char array[] = {'A', 'B', 'C', 'D', 'E'};
char* PointerToArray = array;
char* PointerToChar = &array[0];

cout << "array = " << array << endl;
cout << "PointerToArray = " << PointerToArray << endl;
cout << "PointerToChar = " << PointerToChar << endl;

cout << endl;
cout << "array[2] = " << array[2] << endl;
cout << "PointerToArray[2] = " << PointerToArray[2] << endl;

cout << endl;
cout << "array + 2 = " << array + 2 << endl;
cout << "PointerToArray + 2 = " << PointerToArray + 2 << endl;
cout << "PointerToChar + 2 = " << PointerToChar + 2 << endl;


return 0;
}



No comments:

Post a Comment