Code

#include <stdio.h>

void reassign_based_on_value(int **pp, int *n2_ptr) {
    // Your logic here
    if(**pp % 2 == 0){
        *pp = n2_ptr;
    }
}

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

  • Pointer Setup:
    p initially points to n1.
  • Pass by Reference:
    Send &p (address of pointer) so function can modify p itself.
  • Inside Function:
    • Check if value at *p (→ **pp) is even.
    • If even → reassign *pp = n2_ptr;
    • If odd → do nothing.
  • Print Result:
    *p shows the value of variable pointer currently points to.

 

 

Upvote
Downvote
Loading...

Input

10 50

Expected Output

50