I'm relativly new to Coding and have some Problems understanding how pointers work in combination with arrays (whom on their own I i understand).
I understood that it's possible to create an array of pointers like:
#include <iostream>
using namespace std;
int main() {
int i;
int *pArr[10];
pArr[0]=&i;
return 0;
}
In a Tutorial I then found the following code:
#include <iostream>
using namespace std;
int main() {
char *names[4] = {
"name A",
"name B",
"name C",
"name D"
};
for (int i = 0; i < 4; i++) {
cout << names[i] << endl;
}
return 0;
}
Why is it, that I can assign Multiple chars, or to say a string, like "name A" to a pointer which should point to a char.
Shouldn't I A:
Only be able to assign the Address of a char to each of those 4 pointers I created.
And B:
Only be able to assign a pointer, to one single letter (a char), to each one.
I hope someone can help clear my confusion to some degree.
"name A"'s type actually isconst char*.const2.using std is bad- google that as wellconst char[7]