0

I am trying to understand the logic between the three writing: array, &array and &array[0]:

#include <stdio.h>

void foo(int *a);
void bar(int (*a)[3]);
void baz(int a[3]);

int main(void) {
    int array[] = {1,2,3};

    int* a = array;
    int (*b)[sizeof(array)/sizeof(array[0])] = &array;
    int* c = &array[0];

    printf("%p, %p, %p", a, b, c);
}

I always thought int a[] is a kind-of int *. And in fact it works:

int *p = array;

But the address of a pointer to an int is int**:

int *u;
int **v = &u;

However here, the adresse of array is not int** but int (*)[3]. I am lost.

What does the standard says about &array?

5
  • Lose the notion "int a[] is a kind-of int *" and then there is no confusion. The array of ints is several single ints next to each other in memory. It has an address just like any other variable Commented Aug 22, 2019 at 7:06
  • I would accept that, but what is precisely int a[] then ? Commented Aug 22, 2019 at 7:07
  • dupe of : stackoverflow.com/questions/54807208/… Commented Aug 22, 2019 at 7:09
  • 1
    more info: stackoverflow.com/questions/33775701/… Commented Aug 22, 2019 at 7:10
  • @nowox an array, which I explained in my first comment Commented Aug 22, 2019 at 7:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.