PicoNa
PicoNa

Reputation: 3

(0xC0000005) in clion when running code without debug mode

I've been trying to make a linked list with this code. It works fine when I run it using debug mode (and exits with exit code 0). But when I try to run it or when I Compile the code manually it exits with "Process finished with exit code -1073741819 (0xC0000005)".

num_t *temp = nums;

while (temp -> next){
    temp = temp -> next;
}

temp -> next = (num_t *) malloc(sizeof(num_t *));
temp = temp -> next;
temp -> location[0] = i;
temp -> location[1] = j;
temp -> next = NULL;

num_t is typedef for struct num. and struct num is an structure which has an array of 2 integers (array "location") and a pointer to struct num. nums is the first node of linked list and is initialized before (it's next node is NULL).

I read topics about "Process finished with exit code -1073741819 (0xC0000005)". none of them were useful.

Upvotes: 0

Views: 602

Answers (1)

PicoNa
PicoNa

Reputation: 3

Well, according to @Gerhardh 's comment the problem happened because I allocated insufficient memory for nodes. I was allocating memory only for a pointer, not a pointer and two integers. so changing malloc(sizeof(num_t *)) to malloc(sizeof(num_t)) solved the problem. and at the end I must thank @yano for their detailed explenation.

Upvotes: 0

Related Questions