Is there a way to stop the while loop below from iterating after surpassing 40? I am trying to replicate the linked list concept of iterating while NULL pointer is not found.
int main() {
    int* arr = new int[4]{ 10,20,30,40 };
    //for(int i=0; i<4; ++i) -- works fine
    while (arr) {
        cout << *(arr++) << endl;
    }
        
    delete[] arr; // Free allocated memory
    return 0;
}
 
     
     
     
     
    