#include <stdio.h>

int main() { int a, b, *p1, *p2, *p; a = 1; b = 2; p1 = &a; p2 = &b; if (a < b) { p = p1; p1 = p2; p2 = p; } printf('%d, %d ', a, b); return 0; }

This code swaps the pointers p1 and p2 if a is less than b, but does not swap the values pointed to by p1 and p2. The output will always be '1, 2'.

C Programming: Pointer Swapping and Value Preservation

原文地址: https://www.cveoy.top/t/topic/ol5I 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录