#include #include int string_length(char * my_string) { int counter = 0; while(1) { if (my_string[counter] != 0) { counter++; } else { break; } } return counter; } char * copy_string(char * input) { int length = string_length(input); char * result = (char *) malloc(sizeof(char) * (length + 1)); int i; for (i = 0; i <= length; i++) { result[i] = input[i]; } return result; } struct person { char * name; int age; }; // note that, in contrast to example1.cpp, here the // argument of the foo function is not a pointer. void foo(struct person p1) { p1.age = 30; p1.name = copy_string("john"); } int main() { struct person p; p.name = copy_string("mary"); foo(p); // note that, in contrast to example1.cpp, here p.name // does not change in foo. printf("p.name = %s\n", p.name); }