#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
/*
Questions:
- should the function modify the original pointer
- n1 & n2 are valid integers?
- function prints the value or its handled in main?
- negative integers?
Plan:
1. deref the double pointer to get the value pointed to by p
2. If value is even then reassign *pp to point to n2
3. If value is odd, do nothing (p keeps pointing to n1)
*/