Guest User

Untitled

a guest
Oct 19th, 2018
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. typedef struct {
  2. int *p;
  3. } Mashiro;
  4.  
  5. void fuga(const Mashiro& a)
  6. {
  7. Mashiro b = a; // コピーされる
  8.  
  9. *(b.p) = 20; // アドレスごとコピーされているので、これは a.p に影響する
  10. }
  11.  
  12. int main()
  13. {
  14. Mashiro mashiro;
  15.  
  16. int i = 10;
  17.  
  18. mashiro.p = &i;
  19.  
  20. fuga(mashiro);
  21.  
  22. *(mashiro.p); // => 20;
  23. }
Add Comment
Please, Sign In to add comment