c++ - vs2008调试出错, 结构体变量使用前未初始化.
巴扎黑
巴扎黑 2017-04-17 14:51:35
0
2
731
巴扎黑
巴扎黑

reply all(2)
迷茫

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;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template