c - How to assign null to pointer of struct? -
i not sure i'f specific , clear enough. sick clear doubt. trying assign null value pointer.
given code :
typedef struct date { int year; int month; }date; typedef struct record { char name[20]; char cdate[20]; float quanitity; int barcode; date date; }record; and in main :
record *records = malloc(10 * sizeof(record)); records[0] = null; this doesn't work, when define similliar array of premitive type, illustration int can assign values, or null illustration for
int *avi = malloc(sizeof(int)*10); avi[0] = 3; avi [0] = null; it works fine, i've printed values , seen changes. when same array of pointers struct, defined above can not assign null value..
clueless. using eclipse ide. in advance.
your problem records pointer 10 objects. thus, records[0] first object. cannot set object null.
it appears work int because set int zero, not null.
c arrays eclipse pointers struct
No comments:
Post a Comment