0
How to access the pointer to the character array?? What is the expected output ?
char *name = NULL; name=new char[5]; name[0]='G'; cout<<name; //If you think the output is G PLEASE can you explain me the whole working of it!
3 Answers
+ 3
The indexing in array starts from 0. So the pointer will point to the first element of the array. And your first element that you have assigned is G. So answer is G.
+ 2
When you assign an array to a pointer then always remember that the pointer will point to the first element of the array which is obviously name[0] in your case so G is printed.
+ 1
So name[1] is correct ???