taeyounkim LOG

pointer practice 3 (function to swap numbers) 본문

Career&Study/Coding Practice

pointer practice 3 (function to swap numbers)

taeyounkim 2021. 7. 8. 23:02
728x90

#include <stdio.h>

void swap(int *p, int *q);

int main(void)
{
    int i=1, j=2;
    
    swap(&i, &j);
    
    printf("%d\n", i);
    printf("%d\n", j);
    
    return 0;
}

void swap(int *p, int *q)
{
    int temp;
    temp =  *p;
    *p = *q;
    *q = temp;
}

728x90