I was learning about pointers and pointers to arrays, when I encountered this strange thing.
Can anyone explain why this works?
char str[] = "This is a String";
int *p = str;
while(*p) std::cout<<*p++;
and returns :
but this one generates a nasty error:
int arr[] = {1,2,3,4,5,6,7,8,9};
int *p = arr;
while(*p) std::cout<<*p++<<" ";
like this :
I know that this is undefined behavior, so is there any way to resolve this?