Multiple choice technology security

int main(int argc,char* argv[]){
    int *ptr=new int;
    if(ptr==NULL)   exit(1);
    char *j;
    for(int i=1; i<=4;  i++) {
        j=argv[i];
        int k=atoi(j);
        if (k!=0){
            *ptr=k;
            delete ptr;
        }
    }
}

Will this program execute successfully ?

  1. program works when there is only 1 argument with program.

  2. program works when there are 3 arguments with program.

  3. program works when there are 4 arguments with program.

  4. program never executes successfully.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Inside the loop, ptr is deleted in the first iteration where k != 0. In subsequent iterations, if k != 0 again, the program attempts to dereference and delete the already freed pointer ptr, causing a double-free / undefined behavior. Thus, the program never executes successfully.