Dangling Pointer in C

后端 未结 7 615
别跟我提以往
别跟我提以往 2020-12-07 05:02

I wrote a program in C having dangling pointer.

#include

int *func(void)
{
    int num;
    num = 100;
    return #
}

int func1(void         


        
7条回答
  •  抹茶落季
    2020-12-07 05:46

    It's undefined behavior. It could work correctly on your computer right now, 20 minutes from now, might crash in an hour, etc. Once another object takes the same place on the stack as num, you will be doomed!

提交回复
热议问题