Hi,I have a question about pointers;
char * bf=new char[5];
char* p=bf+5;
Does p-- work? or will p-- make some undefined error? As bf+5 is undefined?
Thanks.
Hi,I have a question about pointers;
char * bf=new char[5];
char* p=bf+5;
Does p-- work? or will p-- make some undefined error? As bf+5 is undefined?
Thanks.
There is nothing undefined about
char* bf=new char[5];
char* p=bf+5;
But p will be pointing off the end of the array. As long as the array is not destroyed, p-- will bring you back to the last element of the array.
p-- in this case is guaranteed to point to the last element of the array, no UB.