nosbor
nosbor

Reputation: 2999

realloc memory Access violation reading location

Probably my brain is not working properly now... I wonder why I receive mentioned error in my code:

int ** zm;
zm = (int**)calloc(1, sizeof(int*));
*zm = (int*)calloc(1, sizeof(int));
*zm[0] = 5;
*zm = (int*)realloc(*zm, 2*sizeof(int));
*zm[1] = 10; // Access violation reading location 0xFFFFFFFFFFFFFFFF

Could someone explain what happend in that code?

Upvotes: 3

Views: 1290

Answers (2)

aks
aks

Reputation: 167

Try *(zm+1) to assign value of second element *(zm+1)=10;

Upvotes: 0

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84189

Wrong indexing, try (*zm)[1] instead. And check for errors from library calls.

Upvotes: 5

Related Questions