Does freeing an uninitialized pointer result in undefined behavior?

前端 未结 4 1327
悲&欢浪女
悲&欢浪女 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:44

    Yes, it does, since you should only free() a pointer that 1. is NULL or 2. you obtained via a call to malloc(), calloc() or realloc().

提交回复
热议问题