/* * malloc.c */ #include #include char *foo(void); int main(int argc, char *argv[]) { char *t; t = foo(); printf("my string says \"%s\"\n", t); printf("the first character is %c\n", *t); free(t); } char *foo(void) { char *s; s = malloc(6); if(s == NULL) { printf("error allocating memory\n"); exit(1); } *s = 'h'; *(s+1) = 'e'; *(s+2) = 'l'; *(s+3) = 'l'; *(s+4) = 'o'; *(s+5) = '\0'; return s; }