fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct node
  5. {
  6. int data;
  7. node *next;
  8. };
  9.  
  10. int main()
  11. {
  12. node *n, *t, *h;
  13.  
  14. n = new node;
  15. n->data = 1;
  16. t = n;
  17. h = n;
  18.  
  19. n = new node;
  20. n->data = 2;
  21. t->next = n;
  22. t = n;
  23.  
  24. n = new node;
  25. n->data = 3;
  26. t->next = n;
  27. t = n;
  28.  
  29. n = new node;
  30. n->data = nullptr;
  31.  
  32.  
  33. n = h;
  34. while(n != nullptr)
  35. {
  36. cout << n->data << endl; // EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  37. n = n->next;
  38. }
  39.  
  40.  
  41.  
  42. return 0;
  43. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:30:12: error: cannot convert ‘std::nullptr_t’ to ‘int’ in assignment
  n->data = nullptr;
            ^~~~~~~
stdout
Standard output is empty