I'm trying to make an array of pointers that points to structures addresses, here's the code:
#include <stdio.h>
#include <stdlib.h>
typedef struct poo {
int a,b;
} poo;
int main() {
struct poo *adres,poo;
poo.a = 2;
I'm wondering why this works :
adres = &poo;
printf("%d\n",adres->a);
and when I try to make an array of pointers it doesn't work :
adres = malloc(4*sizeof(*adres));
adres[0] = &poo;
printf("%d\n",adres[0]->a);
Error :
poo.c: In function ‘main’: poo.c:23:13: error: incompatible types when
assigning to type ‘struct poo’ from type ‘struct poo *’
adres[0] = &poo;
^ poo.c:25:26: error: invalid type argument of ‘->’ (have ‘struct poo’)
printf("%d\n",adres[0]->a);
^