fork download
  1. //C++ snippet
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <iostream>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. struct node{
  10. int val;
  11. node *left;
  12. node *right;
  13. }*root;
  14.  
  15. int main() {
  16.  
  17. node *tmp = (node *)malloc(sizeof(node *));
  18. tmp->val = 5;
  19. tmp->left = NULL;
  20. tmp->right = NULL;
  21. root = tmp;
  22.  
  23. cout<<sizeof(node)<<" "<<sizeof(node*)<<endl;
  24. node *t = (node *)malloc(sizeof(node *));
  25. cout<<"earlier: "<<&root->right<<" "<<root->right<<endl;
  26. t->val = 4;
  27. cout<<"after: "<<&root->right<<" "<<root->right<<endl;
  28. t->left = NULL;
  29. t->right = NULL;
  30. root->left = t;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3228KB
stdin
1 2 5 4
stdout
12 4
earlier: 0x9917010 0
after: 0x9917010 0