what does the function returns with in C program , in case if there is no return statement in the code

后端 未结 3 1239
情书的邮戳
情书的邮戳 2021-01-24 04:40

I made a function on how to reverse a singly linked list recursively in C.

the function is as below.

struct node * reverseSLL2(struct node *p,struct node         


        
3条回答
  •  悲&欢浪女
    2021-01-24 04:56

    I'll bet you're running on a machine where the function result is in a register (EAX on 32-bit x86 for example), and the return value from the recursive call is still sitting in that register when you return without a value by falling off the end of the function. The compiler doesn't have to use that sequence, so it's still Undefined Behavior.

    You can fix your version by simply adding the return to the recursive call:

    return reverseSLL2(temp1,p);
    

提交回复
热议问题