Return value as pointer : Function Return « Function « C Tutorial






#include <stdio.h>

long *myFunction(long* pPay);          

int main(void)
{
  long your_pay = 30000L;             
  long *pold_pay = &your_pay;         
  long *pnew_pay = NULL;              

  pnew_pay = myFunction( pold_pay );
  printf("\nOld pay = $%ld", *pold_pay);
  printf("   New pay = $%ld\n", *pnew_pay);
  return 0;
}

long *myFunction(long *pPay)
{
  *pPay += 10000L;                    
  return pPay;                        
}
Old pay = $40000   New pay = $40000








8.7.Function Return
8.7.1.If the function does not return any value
8.7.2.Return value as pointer
8.7.3.Functions That Return value