Pointers must be initialized before use
int main() { ArrayListPtr list; Init(list); /* //两种改法 ArrayList list; Init(&list) // 以下的操作都不是指针,访问成员要改为`.` //或者 ArrayListPtr list = (ArrayListPtr)malloc(sizeof(ArrayList)); Init(list); */ printf("length: %d\n", list->length); printf("size: %d\n", list->size); return 0; }
The first list is a dirty pointer, does not assign nullptr, and does not point to any legal memory; The second list is a legal ArrayList address;
Pointers must be initialized before use
The first list is a dirty pointer, does not assign nullptr, and does not point to any legal memory;
The second list is a legal ArrayList address;