Home > Back-end >  Would like to ask you how to change this bug
Would like to ask you how to change this bug

Time:10-02

Just learning data structure, this I change for a long time can't

CodePudding user response:

I put the int data [maxsize] to int * data can run, want to ask why is this?

CodePudding user response:

The int data [maxsize] is an array, the array of memory is program (the length of the array to ensure user), once the program is a good memory, its can't change the (the equivalent of a constant pointer), so you can't use data=https://bbs.csdn.net/topics/XXX to change the address of the array (that is, data=(int *) malloc () the cause of the error), can only use the data [I]=XXX to change an array element

Int * data pointer, it is need user to initialize pointer pointing to, if the memory is not allocated good point to, will automatically apply for memory, that is, data=https://bbs.csdn.net/topics/(int *) malloc () is not the cause of the error (which is normal legal initializing pointer)
  • Related