Pages

swap

en C

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

int main()
{
    int x=1, y=2;

    swap(&x, &y);
    printf("x = %d, y = %d", x, y);
    return 0;
}

➥ code dans Pythontutor

js


let swap = (x,y) => [y,x];

let x=1, y=2;
[x,y] = swap(x,y);
console.log(`x=${x} y=${y}`)

➥ code dans Pythontutor