0
#include <stdio.h>
#include <stdlib.h>
int* sum(int* num1,int* num2);
int main(){
  int a = 10000;
  int b=2000;
  int *A = sum(&a, &b);
  return 0;
}
int* sum(int* num1,int* num2){
  int x = (*num1)+(*num2);
  return &x;
      \\(^^)its shows that this line is the only problem. (Core dumped).
}

I am learning about pointers thats why its all pointers. :)

Feey 1
  • 1
  • x is a local variable to sum. It is gone when you rleave the routine. – stark Feb 16 '22 at 21:36
  • [Note the compiler warning](https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(lang:c%2B%2B,source:'int*+sum(int*+num1,int*+num2)%7B%0A++int+x+%3D+(*num1)%2B(*num2)%3B%0A++return+%26x%3B%0A++++++%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231')),k:34.502375442953706,l:'4',n:'0',o:'',s:0),(g:!((h:compiler,i:(compiler:g112,lang:c%2B%2B),l:'5',n:'0',o:'x86-64+gcc+11.2')),header:(),k:33.193840103251276,l:'4',n:'0',o:'',s:0),(g:!((h:output,i:(compiler:1,editor:1),l:'5',n:'0',o:'Output')),k:32.303784453795004,l:'4',n:'0',o:'',s:0)),l:'2',n:'0',o:'')),version:4). – Raymond Chen Feb 16 '22 at 21:38

0 Answers0