[圖解C] Example 814: return pointer variable

// Example 814: return pointer variable

#include <stdio.h>
#include <stdlib.h>

// using '*' to return pointer variable
int *addition();

int main()
{
    int *ptr;
    ptr = addition();
    printf("*ptr = %d\n", *ptr);
   
    system("pause");
    return 0;
}

// using '*' to return pointer variable
int *addition()
{
    int a, b;
    int *xadrs;
   
    xadrs = &a;
   
    printf("enter 2 integers: ");
    scanf("%d  %d", &a, &b);
   
    a = a+b;
   
    // xadrs points to the address of int variable a
    return xadrs;
}