Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer value of *x &x and x

Tags:

c

pointers

suppose this code:

main()
{
    int *x;
    *x = 3;

    printf("%d %d %d\n", *x, &x, x);
    // output 3 5448392 2293524
}

if *x is the value; &x the addres; what does mean that value of x?

like image 510
Fabricio Avatar asked Nov 28 '22 09:11

Fabricio


1 Answers

  • *x is the value (correct)
  • x is the address of the value. EDIT In your case, this address is uninitialized, so it is not pointing anywhere in particular (thanks Keith Nicholas for mentioning this).
  • &x is the address of the [pointer that should contain the] address of the value.

(it's worth pointing out that your program may crash :)

like image 89
Sergey Kalinichenko Avatar answered Dec 21 '22 07:12

Sergey Kalinichenko