Does freeing an uninitialized pointer result in undefined behavior?

前端 未结 4 1360
悲&欢浪女
悲&欢浪女 2021-01-21 09:39

If you have a pointer that is not initialized and, by mistake, try to free it, is this going to result in undefined behavior?

Like:

int main(void){

             


        
4条回答
  •  耶瑟儿~
    2021-01-21 10:27

    Yes, because accessing any uninitialised variable provokes undefined behaviour.

    This includes passing an uninitialise pointer tofree(). This itself also includes the case where the uninitialise pointer "by accident" may have a value equal to NULL.

提交回复
热议问题