There are actually three errors and one potential pitfall in this code.
First, you are creating an uninitialized pointer to a structure. I think you meant do just say:
Second, you are creating a buffer of 4 bytes, the size of an int, instead of "10".
Code:
st->s = (char *) malloc(sizeof(10));
If you wanted to create an array of 10 bytes, you would just say
Code:
st->s = (char *) malloc(10);
or
Code:
st->s = (char *) malloc(10 * sizeof(char));
That is still risky though as it is not tied to the length of the string (if you later changed the string length, you would also have to update the buffer). So better than that, you could write
Code:
st->s = (char *) malloc(strlen("bargi") * sizeof(char) + 1 /* terminator */ );
Still better though, you could use the strdup function, which does all that for you:
Code:
st->s = (char *) strdup("bargi");
The third bug is that after creating memory for a string, you leaked that buffer when you assigned st->s to a new const string "bargi".
You don't state the actual crash, but it was probably due to dereferencing the uninitialized st pointer