return_malloced.c 354 B

123456789101112131415
  1. // To test that when gimmestring function malloc's data, can safely return it to the outer, without causing any compiler warning.
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. char *gimmestring() {
  6. char *s = malloc(11*sizeof(char));
  7. strcpy(s, "havastring");
  8. return s;
  9. }
  10. void main(int argc, char **argv) {
  11. printf("%s\n", gimmestring());
  12. }