, :
C int x int *x ( )
. .data .bss ( static , ).
- . *x=1, SIGSEGV, - . C :
$ cat stack.c
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
int j;
int k;
int *l;
int *m;
int *n;
printf("i: %d\n", i);
printf("j: %d\n", j);
printf("k: %d\n", k);
printf("l: %p\n", l);
printf("m: %p\n", m);
printf("n: %p\n", n);
return 0;
}
$ make stack
cc stack.c -o stack
$ ./stack
i: 0
j: 0
k: 32767
l: 0x400410
m: (nil)
n: 0x4005a0
l n - - , , . - , , , . , .
m , NULL - , , , .
. . .
L - , - , C: R- ( ) L- ( ) .
, :
int a;
a = 3;
3 , a.
:
int b;
b = a;
, , a, , b.
:
int *ap;
ap=malloc(sizeof int);
*ap=3;
ap= ap. ap . *ap= . ap ; , ap, .
When you later use the pointer, you can choose which of the two values associated with the pointer used: either the actual contents of the pointer, or the value that the pointer points to:
int *bp;
bp = ap;
int *bp;
bp = malloc(sizeof int);
*bp = *ap;
I found the assembly much easier than C for many years because I found the difference between foo = malloc();and *foo = value;confusing. I hope I found what baffled you, and seriously hope that I will not make it worse.