Address of array - difference between having an ampersand and no ampersand

后端 未结 4 1043
天命终不由人
天命终不由人 2020-12-11 02:38

I have a struct that looks like this:

struct packet {
  int a;
  char data[500];
};
typedef struct packet packet_t;

I\'m a little confused

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 03:13

    That's because array decays to a pointer pointing to first element in the sequence. So, packet.data address location is same as &packet.data or &packet.data[0].

提交回复
热议问题