fork download
  1. #include <stdlib.h>
  2. #include <memory>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. int* foo = (int*)malloc(sizeof(int) * 10);
  8. for (int i=0; i<10; i++)
  9. foo[i] = i;
  10. for (int i=0; i<10; i++)
  11. std::cout << foo[i];
  12. std::cout << std::endl;
  13. free(foo);
  14.  
  15. std::unique_ptr<int[], std::default_delete<int[]> > bar(new int[10]);
  16. for (int i=0; i<10; i++)
  17. bar[i] = i;
  18. for (int i=0; i<10; i++)
  19. std::cout << bar[i];
  20. std::cout << std::endl;
  21. }
  22.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0123456789
0123456789