Code

#include <stdio.h>

void reassign_based_on_value(int **pp, int *n2_ptr) {
    // Your logic here
    //**pp points to a pointer
    //I need to choose whether I want pp to point to the address of n1 or the address of n2
    //If value at **pp is even, change pp to point to n2
    if(**pp % 2 ==0){
        *pp = n2_ptr; //value of pp (address of pointer) now points to address of &n2 which = n2_ptr
    }
    //printf("%d\n",**pp);
}

int main() {
    int n1, n2;
    scanf("%d %d", &n1, &n2);

    int *p = &n1;

    reassign_based_on_value(&p, &n2);

    printf("%d", *p);

    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

10 50

Expected Output

50