Advertisement
wendy890711

指標

Mar 29th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int name=5;
  7. int *ptr_name=&name;
  8. cout<<"address of name:"<<&name<<endl;
  9. cout<<"&ptr_name:\t"<<&ptr_name<<endl;
  10. cout<<"pr_name:\t"<<ptr_name<<endl;
  11. cout<<"*ptr_name:\t"<<*ptr_name<<endl;
  12.  
  13. int other=10;
  14. ptr_name=&other;
  15. cout<<"\n\n***point to other\n";
  16. cout<<"address of name:"<<&name<<endl;
  17. cout<<"address of other:"<<&other<<endl;
  18. cout<<"&ptr_name:\t"<<&ptr_name<<endl;
  19. cout<<"pr_name:\t"<<ptr_name<<endl;
  20. cout<<"*ptr_name:\t"<<*ptr_name<<endl;
  21.  
  22. other=5;
  23. cout<<"\n\n***other=5\n";
  24. cout<<"value of other:\t"<<other<<endl;
  25. cout<<"*ptr_name:\t"<<*ptr_name<<endl;
  26.  
  27. *ptr_name=100;
  28. cout<<"\n\n*** *ptr_name=100\n";
  29. cout<<"value of other:\t"<<other<<endl;
  30. cout<<"*ptr_name:\t"<<*ptr_name<<endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement