Quick C Style Question

Posted by LearningC on Stack Overflow See other posts from Stack Overflow or by LearningC
Published on 2010-04-18T23:57:36Z Indexed on 2010/04/19 0:03 UTC
Read the original article Hit count: 101

Filed under:
|

Which is considered better style?

int set_int(int *source){
 *source = 5;
 return 0;
}

int main(){
 int x*;
 set_int(x);
}

OR

int *set_int(){
 int *temp = NULL;
 temp = malloc(sizeof (int));
 *temp = 5;
 return temp;
}

int main(){
 int *x = set_int();
}

Coming for a higher level programming background I gotta say I like the second version more. Any, tips would be very helpful. Still learning C.

© Stack Overflow or respective owner

Related posts about c

    Related posts about best-practices