Home  >  Q&A  >  body text

c++ - vs2008调试出错, 结构体变量使用前未初始化.

巴扎黑巴扎黑2763 days ago700

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 14:53:35

    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;
    }

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 14:53:35

    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;

    reply
    0
  • Cancelreply