title: in C how to pass local function variable value to another function and print value without errors
body: <pre><code>#include &lt;stdio.h&gt; 
  #include &lt;stdlib.h&gt;
  
  int give_options();
  
  int give_options(){
  
      printf("===== MENU 1 =====\n");
  
      printf("&gt; store new customer :\t\tenter 1\n");
      printf("&gt; view a customer :\t\tenter 2\n");
      printf("&gt; view all customers :\t\tenter 3\n");
      printf("&gt; exit program :\t\tenter 4\n ");   
  
  
      int ipt = malloc(sizeof(int));
      scanf("%d",&amp;ipt);
  
      return ipt;
  }
  
  
  int main(){
      int dec = give_options();
  
      printf("decision is: %d", dec);     
  
  
      getchar();
  }
  </code></pre>
  
  <p>Ive started to code in C recently in Ubuntu
  im trying to return the value a local variable of one function and have it passed to another
  function. I have read that since local variables are assigned to stack the value will no longer
  exist after function returns, and that I have to allocate memory in heap using malloc.</p>
  
  <p>when I compile I get this warning: </p>
  
  <pre><code>initialization makes integer from pointer without a cast
  [-Wint-conversion] int ipt = malloc(sizeof(int));
  </code></pre>
  
  <p>when I adjust this to int ipt = (int)malloc(sizeof(int)); -I get:</p>
  
  <pre><code>warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  int ipt = (int)malloc(sizeof(int));
  </code></pre>
  
  <p>What is the correct thing to do here?</p>
  
  <p>I'm also having trouble with scanf since I switched to coding in Ubuntu.
  I tried a different way, trying to use pointers:</p>
  
  <pre><code>#include &lt;stdio.h&gt; 
  #include &lt;stdlib.h&gt;
  
  int* give_options();
  
  int* give_options(){
  
      printf("===== MENU 1 =====\n");
  
      printf("&gt; store new customer :\t\tenter 1\n");
      printf("&gt; view a customer :\t\tenter 2\n");
      printf("&gt; view all customers :\t\tenter 3\n");
      printf("&gt; exit program :\t\tenter 4\n ");   
  
      int* ipt; 
      ipt = malloc(sizeof(int));
      scanf("d",&amp;ipt);
  
      return ipt;
  }
  
  
  int main(){
      int* dec = give_options();
  
      printf("decision is: %d", dec); 
  
      getchar();
  }
  </code></pre>
  
  <p>compiling this gives me following errors:</p>
  
  <pre><code>warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat=]
    scanf("%d",&amp;ipt);
  
  warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
    printf("decision is: %d", dec);
  </code></pre>
  
  <p>which approach is right and which one works?</p>