Hi all! I have the following code:
The definition of fill_up_A could ALSO be:
Now my question is, which function definition is a better way of filling up the structure? Is there a difference in the two ways of implementing this at all? Or are they absolutely similar and any subsequent operations on a->string would have exactly the same effect in both scenarios?
Thanks in advance,
Sid
Code:
typedef struct A { char* string; }A; //Function prototype void fill_up_A(A* a); int main() { A var_A; fill_up_A( &var_A); printf("String is : %s", var_A.string); return 1; } //Function definition void fill_up_A(A* a) { a->string = "Hello World!"; }
The definition of fill_up_A could ALSO be:
Code:
//Function definition void fill_up_A(A* a) { a->string = (char *)malloc(20); strcpy(a->string, "Hello World!"); }
Thanks in advance,
Sid
Comment