Devlog/Coding Practice

[C++][Introduction] Pointer

FATKITTY 2021. 8. 3. 01:20
반응형

https://www.hackerrank.com/challenges/c-tutorial-pointer/problem

 

 

#include <stdio.h>
#include <cstdlib>

void update(int *a,int *b) {
    // Complete this function    
    int a_update, b_update;
    a_update = (*a) + (*b);
    b_update = abs((*a) - (*b));
    *a = a_update;
    *b = b_update;
}

int main() {
    int a, b;
    int *pa = &a, *pb = &b;
    
    scanf("%d %d", &a, &b);
    update(pa, pb);
    printf("%d\n%d", a, b);

    return 0;
}

 

반응형