Dangling Pointer in C

后端 未结 7 625
别跟我提以往
别跟我提以往 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:52

    Returning a pointer to a local variable yields undefined behaviour, which means that anything the program does (anything at all) is valid. If you are getting the expected result, that's just dumb luck.

提交回复
热议问题