Pointer variable & variable and variable difference

Asked 2 years ago, Updated 2 years ago, 37 views

int main(void)
{ 

   int a[10] = { 0 };

   int var = 10;

   int* variable= &var;

   printf("Results: &variable=%p, variable=%p, *variable=%p, var=%p\n",
                 &variable, variable, *variable,  var);

   printf("Results: a=%p, &a=%p\n", a, &a);

}

In inta[] = {0};, the address values of a and &a were the same as the address values of a[0]. So I thought the pointer variable name also pointed to me, but I don't know why the values of &variable and variable are different.

pointer c

2022-09-21 11:14

1 Answers

int main(void)
{ 
    int a[10] = { 0 };
    int var = 10; 
    int* variable= &var;
    printf("variable %x\n", &variable);
    printf("variable %x\n", variable);
    printf("variable %d\n", *variable);

    printf("var %x\n", &var);
    printf("var %d\n", var);
}

//Results
Address value of variable c75854a0 //variable
Value stored in variable c75854ac //variable
variable 10 //What is stored in the stored value (address)
Address value of var75854ac //var
Value stored in var 10 //var

variable (0xc75854a0) stores the address of var (0xc75854ac).

Therefore, &variable (address value 0xc75854a0 of variable) and the value entered in variable (0xc75854ac) are different.


2022-09-21 11:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.