Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Animal {
  6. private:
  7.     const int age;
  8.     string name;
  9.     int *carne;
  10.  
  11. public:
  12.     Animal(const int& age, const string& name) : age(age), name(name) {
  13.         carne = new int(10);
  14.         cout << "io's constructor";
  15.  
  16.     }
  17.  
  18.     virtual ~Animal() {
  19.         cout << "io's destructor";
  20.         delete carne;
  21.     }
  22. };
  23.  
  24. int p = 9;
  25.  
  26. void thisWillChangeTheValue(const int& a) {
  27.     p = a;
  28. }
  29.  
  30. void thisWillNOTChangeTheValue(int a) {
  31.     int tempA = a;
  32.     tempA = 10;
  33. }
  34.  
  35. void thisWillChangeTheValueC(int* a) {
  36.     *a = 6;
  37. }
  38.  
  39. int main() {
  40. //    int a = 50;
  41. //
  42. //    cout << &a << " " << a << endl;
  43. //
  44. //
  45. //    int* ptoa;
  46. //    ptoa = &a;
  47. //    *ptoa = 1000;
  48. //
  49. //    cout << &a << " " << a << endl;
  50. //
  51. //    cout << ptoa << " " << *ptoa << endl;
  52. //
  53. //    thisWillChangeTheValueC(ptoa);
  54. //
  55. //    cout << ptoa << " " << *ptoa << endl;
  56. //
  57.  
  58.  
  59. //    int age = 10;
  60. //    string name = "anal";
  61. //
  62. //    Animal anim = Animal(age, name);
  63. //
  64.  
  65.  
  66.     int a = 5;
  67.  
  68.     cout << a << endl;
  69.  
  70.     thisWillChangeTheValueC(&a);
  71.  
  72.     cout << a << endl;
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement