Example 1 — Two pointers to the same variable
Writes through either pointer are seen by both.
#include <stdio.h>
int main(void) {
int n = 7;
int *a = &n;
int *b = &n;
*a = *a + 1;
printf("n = %d\n", n);
*b = *b * 10;
printf("n = %d, *a = %d\n", n, *a);
printf("a == b: %d\n", a == b);
return 0;
} How It Works
aandbhold the same address.*a + 1makesn8;*b * 10makes it 80.- Pointer equality compares addresses.
