I'm beginning to learn about pointers in C++ and wrote the below code to practice accessing elements in an array using them.
using namespace std;
char a[] = {'A', 'B'};
char* p = a;
cout << "ARRAY IS " << sizeof(a) << " BYTES." << endl;
cout << "CHARACTER IS " << sizeof(a[0]) << " BYTES." << endl;
cout << "THEREFORE LENGTH IS " << (sizeof(a) / sizeof(char)) << " ELEMENTS." << endl << endl;
cout << "INDEX 0: " << *p << endl;
p++;
cout << "INDEX 1: " << *p << endl;
p++;
cout << "INDEX ?: " << *p << endl;
p++;
cout << "INDEX ??: " << *p << endl;
return 0;
I understand that the array is only two elements long, but tried incrementing the pointer anyway.
How come when I do this the ╟ character is printed to the console?
I'm using Visual Studio as my IDE.