0

So I understand that the array name represents the first address of the array. Thus, printf("%d", name5); should return an address. However, I realized printf("\n%d", &name5); returns the same address as the previous expression.

Does &name5 represent "address of an address"? How does this work?

I also realized this &array_name syntax wouldn't work on malloc. Would appreciate any explanation why this may be the case.

    char name5[10] = "Matt";
    printf("%d", name5);
    printf("\n%d", &name5);

    //char* name2 = (char*)malloc(10);
    //scanf("%s", &name2); // &pointer
    //printf("%s", name2); //error
  • `%d` is for `int` values, not pointers. Use `%p` to print pointers/addresses, with the pointer/address cast to `void *`: `printf("%p", ( void * ) name5);` – Andrew Henle Dec 13 '22 at 14:50
  • First, it is not the name of an array that is transformed to an address but rather the **value** of this array is transformed to the address. Additionally, `&name5` is not *address of address* but rather an address of an array. – tstanisl Dec 13 '22 at 16:16

0 Answers0