Code

// // You are given two integer variables: n1 and n2.
// // ptr --> n1.
// // &ptr ---> function (int **):
// // If the value at pointer is even, reassign it to point to n2.
// // If the value is odd, keep pointing to n1.
// // Finally, print the value where pointer points.

// #include <stdio.h>

//    int n1,n2;

// void reassign_pointer(int** pp2,int *tmp){
//     if((**pp2)%2 == 0){
//         *pp2 = &n2;
//     }
// }


// int main(){
//     scanf("%d%d",&n1, &n2); 
//     int *ptr = &n1; 
    
//     reassign_pointer(&ptr,&n2); 
//     printf("%d",*ptr); 
    
//     return 0;
// }
#include <stdio.h>

void reassign_based_on_value(int **pp, int *n2_ptr) {
    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

 

 

 

Upvote
Downvote
Loading...

Input

10 50

Expected Output

50