fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. // A typical data structure we use in Data Structures in C
  6. typedef struct {
  7. int importance;
  8. char taskName[80];
  9. } UserData, *UserDataPtr;
  10.  
  11. // the test main shows you how to dynamically allocate memory
  12. // to hold an instance of a UserData that you can use.
  13. // If the allocation fails, the program will automatically close
  14. // after logging the file name and the line number of the assertion
  15. // that failed.
  16. int main ()
  17. {
  18. // allocate memory
  19. UserDataPtr UDP = (UserDataPtr) malloc (sizeof(UserData));
  20. // make sure the allocation worked and exit if it failed
  21. assert(UDP != NULL); // use assert to verify !NULL
  22. printf ("Allocation worked\n");
  23. // free up the memory
  24. free (UDP);
  25. return 0;
  26.  
  27. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Allocation worked