#include <stdio.h> #include <stdlib.h> void swap(int* a, int* b){ int tmp = *b; *b = *a; *a = tmp; } int main(void) { int a = 2; int b = 3; swap(&a, &b); printf("%d %d\n", a, b); return 0; }
void swap(int& a, int& b){ int tmp = b; b = a; a = tmp; } int main(void) { int a = 2; int b = 3; swap(a, b); printf("%d %d\n", a, b); return 0;
s是字符数组的起始地址
arr[-1],arr[-2]表示arr[0]之前的两个元素
#include <stdio.h> #include <stdlib.h> int main(void) { int c[2] = {0,0}; printf("%d %d\n", c[-1], c[-2]); return 0; }
输出:
32767 -502976128