Why reverse the order of printf() gives different output?

前端 未结 2 1926
南笙
南笙 2021-01-29 12:09
#include 
int ∗addition(int a, int b){
    int c = a + b ;
    int ∗d = &c ;
    return d ;
}

int main (void) {
   int result = ∗(addition(1, 2));
           


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 12:33

    You're returning a pointer to a local variable, which gets deallocated after the function exits (and thus invokes undefined behavior).

提交回复
热议问题