Hi,

 When we want to return a (char*) type from a function what should we do ?

 Should be done allocation for the variable and after that return those
variable !?
 As we shouldn't(?) free up that variable within the function what should
we do ? 


char *foo ( )
{
  char *xpto ;

  xpto = malloc(30*sizeof(char)) ;

  . . . .

  return xpto ;
}



/*  This case (1) */
main()
{
 
 printf("\n %s", foo() ) ;
 return 0 ;
}


/* This case (2)*/
main()
{
  char *exp ;

  exp = foo() ;

  printf("\n %s", exp);
  free(exp); 
  
  return(0) ;
}

 Which is the most correct ? The second !?
 
 Thanks.

 Best regards,
   Nuno Carvalho


иииииииииииииииииииииииииииииииии
   Nuno Emanuel F. Carvalho
 Dep. Informatics Engineering
    University of Coimbra

  PGP key available at finger
иииииииииииииииииииииииииииииииии

Reply via email to