7
I wonder if it is possible to start this structure type pointer with an address, without needing to point to another variable, or allocate memory.
typedef struct{
char nome[20];
int idade;
}pessoa;
pessoa leonardo;
pessoa *p;
p = &leonardo;
p->idade = 23;
printf("%d", p->idade);
Or allocating memory.
pessoa *p = malloc(sizeof(pessoa));
It is possible yes, but it only makes sense if this address is mapping some device, whose data layout is the same as struct
– C. E. Gesser
A second struct?
– user56294
Look at the answer that has already been given below. You can do this, but it is assumed that at 1234 there are 20 bytes representing the name plus 4 representing age as a
int
. If not, anything can happen.– C. E. Gesser