current position:Home>Why does vs2019 allocate an empty piece of malloc space?

Why does vs2019 allocate an empty piece of malloc space?

2022-01-27 04:33:25 CSDN Q & A

The phenomenon and background of the problem

Allocate space to the pointer , Direct error reporting is null pointer , But I've checked it before. There should be no problem

img




Refer to the answer 1:

You need to instantiate new after , Use in assignment .




Refer to the answer 2:



Refer to the answer 3:

Your check is just out of print memory , No return . Should be

PtrToAdjNode NewNode0 = (PtrToAdjNode)malloc(sizeof(struct AdjNode));PtrToAdjNode NewNode1 = (PtrToAdjNode)malloc(sizeof(struct AdjNode));if (NewNode0 == NULL || NewNode1 == NULL) {    printf(" Out of memory \n");    free(NewNode0); //  Free up memory to prevent memory leakage , It can be NULL The pointer     free(NewNode1);    return;}// ...



Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270433232942.html

Random recommended