{"id":10460,"date":"2024-02-01T11:36:02","date_gmt":"2024-02-01T11:36:02","guid":{"rendered":"https:\/\/adelnasim.com\/docs\/courses\/oop\/new-delete\/"},"modified":"2024-04-07T01:19:43","modified_gmt":"2024-04-07T01:19:43","slug":"new-delete","status":"publish","type":"docs","link":"https:\/\/adelnasim.com\/ar\/docs\/courses\/oop\/new-delete\/","title":{"rendered":"\u0623\u062f\u0627\u0629 New \u0648\u0623\u062f\u0627\u0629 Delete"},"content":{"rendered":"<p>\u0641\u064a \u0627\u0644\u0628\u0631\u0645\u062c\u0629 \u0627\u0644\u0643\u0627\u0626\u0646\u064a\u0629 (OOP) \u0645\u0639 \u0644\u063a\u0629 C++\u060c \u062a\u0644\u0639\u0628 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a Pointers \u062f\u0648\u0631\u064b\u0627 \u062d\u0627\u0633\u0645\u064b\u0627 \u0641\u064a \u0625\u062f\u0627\u0631\u0629 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0648\u0627\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u0649 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627. \u0641\u064a\u0645\u0627 \u064a\u0644\u064a \u0634\u0631\u062d \u0645\u0648\u062c\u0632 \u0644\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0641\u064a \u0633\u064a\u0627\u0642 OOP \u0641\u064a C++:<\/p>\n<p><strong>\u062a\u0639\u0631\u064a\u0641:<\/strong><\/p>\n<p>\u0627\u0644\u0645\u0624\u0634\u0631 Pointer \u0647\u0648 \u0645\u062a\u063a\u064a\u0631 \u064a\u062d\u0645\u0644 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0645\u062a\u063a\u064a\u0631 \u0622\u062e\u0631. \u0641\u064a \u0644\u063a\u0629 C++\u060c \u064a\u0645\u0643\u0646 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0644\u062a\u062e\u0632\u064a\u0646 \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u0627\u0644\u062a\u064a \u062a\u0645 \u0625\u0646\u0634\u0627\u0624\u0647\u0627 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627 \u0639\u0644\u0649 \u0627\u0644\u0640heap.<\/p>\n<p><strong>\u0645\u062b\u0627\u0644 1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main()\r\n{\r\n    int var1 = 11;\r\n    int var2 = 22;\r\n    cout &lt;&lt; &amp;var1 &lt;&lt; endl;\r\n    cout &lt;&lt; &amp;var2 &lt;&lt; endl;\r\n    \r\n    int *ptr;\r\n    ptr = &amp;var2;\r\n    *ptr = 5000;\r\n    cout &lt;&lt; *ptr &lt;&lt; endl;\r\n    cout &lt;&lt; var2 &lt;&lt; endl;\r\n}<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0644\u0645\u0639\u0627\u0644\u062c\u0629 \u0627\u0644\u0645\u062a\u063a\u064a\u0631\u0627\u062a \u0648\u0627\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u0649 \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062e\u0627\u0635\u0629 \u0628\u0647\u0627.<\/p>\n<ol>\n<li>\u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0648\u062a\u0641\u0639\u064a\u0644 \u0627\u0644\u0645\u062a\u063a\u064a\u0631:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int var1 = 11;\r\nint var2 = 22;\r\n<\/pre>\n<p>\u062a\u0645 \u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0645\u062a\u063a\u064a\u0631\u064a\u0646 \u0635\u062d\u064a\u062d\u064a\u0646\u060c var1 \u0648var2\u060c \u0648\u0625\u0639\u0637\u0627\u0626\u0647\u0645\u0627 \u0627\u0644\u0642\u064a\u0645\u062a\u064a\u0646 11 \u064822\u060c \u0639\u0644\u0649 \u0627\u0644\u062a\u0648\u0627\u0644\u064a.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cout &lt;&lt; &amp;var1 &lt;&lt; endl;\r\ncout &lt;&lt; &amp;var2 &lt;&lt; endl;\r\n<\/pre>\n<p>\u062a\u062a\u0645 \u0637\u0628\u0627\u0639\u0629 \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 var1 \u0648var2 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0627\u0645\u0644 \u062a\u0634\u063a\u064a\u0644 \u0639\u0646\u0648\u0627\u0646 (&amp;). \u064a\u0643\u0634\u0641 \u0647\u0630\u0627 \u0639\u0646 \u0627\u0644\u0645\u0648\u0627\u0642\u0639 \u0641\u064a \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u062d\u064a\u062b \u064a\u062a\u0645 \u062a\u062e\u0632\u064a\u0646 \u0647\u0630\u0647 \u0627\u0644\u0645\u062a\u063a\u064a\u0631\u0627\u062a.<\/li>\n<li>\u0625\u0639\u0644\u0627\u0646 \u0627\u0644\u0645\u0624\u0634\u0631 \u0648\u062a\u0639\u064a\u064a\u0646 \u0642\u064a\u0645\u062a\u0647:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *ptr;\r\nptr = &amp;var2;\r\n<\/pre>\n<p>\u062a\u0645 \u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644\u0645\u0624\u0634\u0631 ptr \u0645\u0646 \u0627\u0644\u0646\u0648\u0639 int. \u0648\u062a\u0645 \u062a\u0639\u064a\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 var2 \u0644\u0644\u0645\u0624\u0634\u0631 ptr.<\/li>\n<li>\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631 \u0644\u062a\u0639\u062f\u064a\u0644 \u0627\u0644\u0645\u062a\u063a\u064a\u0631:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">*ptr = 5000;\r\n<\/pre>\n<p>\u064a\u062a\u0645 \u062a\u063a\u064a\u064a\u0631 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u062a\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647\u0627 ptr \u0625\u0644\u0649 5000. \u0648\u0628\u0645\u0627 \u0623\u0646 ptr \u064a\u0634\u064a\u0631 \u0625\u0644\u0649 \u0639\u0646\u0648\u0627\u0646 var2\u060c \u0641\u0625\u0646 \u0647\u0630\u0627 \u064a\u0639\u062f\u0644 \u0623\u064a\u0636\u064b\u0627 \u0642\u064a\u0645\u0629 var2.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0624\u0634\u0631 \u0648\u0627\u0644\u0645\u062a\u063a\u064a\u0631 \u0627\u0644\u0630\u064a \u062a\u0645 \u062a\u0639\u062f\u064a\u0644\u0647:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cout &lt;&lt; *ptr &lt;&lt; endl;\r\ncout &lt;&lt; var2 &lt;&lt; endl;\r\n<\/pre>\n<p>\u062a\u062a\u0645 \u0637\u0628\u0627\u0639\u0629 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0634\u0627\u0631 \u0625\u0644\u064a\u0647\u0627 \u0628\u0648\u0627\u0633\u0637\u0629 ptr (5000) \u0648\u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0639\u062f\u0644\u0629 \u0644\u0640 var2. \u064a\u062c\u0628 \u0623\u0646 \u062a\u0643\u0648\u0646 \u0643\u0644\u062a\u0627 \u0627\u0644\u0642\u064a\u0645\u062a\u064a\u0646 \u0645\u062a\u0645\u0627\u062b\u0644\u062a\u064a\u0646\u060c \u062d\u064a\u062b \u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631 \u0644\u062a\u0639\u062f\u064a\u0644 \u0645\u062d\u062a\u0648\u0649 var2.<\/li>\n<\/ol>\n<p>\u0642\u062f \u062a\u0628\u062f\u0648 \u0645\u062e\u0631\u062c\u0627\u062a \u0627\u0644\u0643\u0648\u062f \u0643\u0645\u0627 \u064a\u0644\u064a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">0x7fff5fbff628  \/\/ Memory address of var1\r\n0x7fff5fbff624  \/\/ Memory address of var2\r\n5000             \/\/ Value pointed to by ptr\r\n5000             \/\/ Modified value of var2\r\n<\/pre>\n<p>\u0642\u062f \u062a\u062e\u062a\u0644\u0641 \u0639\u0646\u0627\u0648\u064a\u0646 \u0648\u0642\u064a\u0645 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u0642\u064a\u0642\u0629 \u0648\u0641\u0642\u064b\u0627 \u0644\u0644\u0646\u0638\u0627\u0645 \u0648\u0627\u0644\u0645\u062a\u0631\u062c\u0645.<\/p>\n<p><strong>\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629:<\/strong><\/p>\n<p>\u063a\u0627\u0644\u0628\u064b\u0627 \u0645\u0627 \u064a\u062a\u0636\u0645\u0646 OOP \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646\u0627\u062a \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0627\u0645\u0644 \u0627\u0644\u062a\u0634\u063a\u064a\u0644 new \u0644\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629. \u062a\u064f\u0633\u062a\u062e\u062f\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0644\u062a\u062e\u0632\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/p>\n<p><strong>\u062d\u0630\u0641 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629:<\/strong><\/p>\n<p>\u0639\u0646\u062f\u0645\u0627 \u0644\u0627 \u062a\u0643\u0648\u0646 \u0647\u0646\u0627\u0643 \u062d\u0627\u062c\u0629 \u0644\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629\u060c \u064a\u062c\u0628 \u062d\u0630\u0641\u0647\u0627 \u0628\u0634\u0643\u0644 \u0635\u0631\u064a\u062d \u0644\u062a\u062c\u0646\u0628 \u062a\u0633\u0631\u0628 \u0627\u0644\u0630\u0627\u0643\u0631\u0629. \u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0639\u0627\u0645\u0644 delete.<\/p>\n<p><strong>\u0645\u062b\u0627\u0644 2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    int *p;\r\n    p = new int;\r\n    *p = 10;\r\n    cout &lt;&lt; p &lt;&lt; endl;\r\n    delete p;\r\n}<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 \u0648\u0625\u0644\u063a\u0627\u0621 \u0627\u0644\u062a\u062e\u0635\u064a\u0635 \u0644\u0645\u062a\u063a\u064a\u0631 \u0639\u062f\u062f \u0635\u062d\u064a\u062d. \u0648\u0641\u064a\u0645\u0627 \u064a\u0644\u064a \u0634\u0631\u062d \u0644\u0644\u0643\u0648\u062f:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    \/\/ Declare a pointer variable\r\n    int *p;\r\n\r\n    \/\/ Allocate memory for an integer on the heap\r\n    p = new int;\r\n\r\n    \/\/ Assign a value to the dynamically allocated integer\r\n    *p = 10;\r\n\r\n    \/\/ Print the address of the dynamically allocated memory\r\n    cout &lt;&lt; p &lt;&lt; endl;\r\n\r\n    \/\/ Deallocate the dynamically allocated memory\r\n    delete p;\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u0634\u0631\u062d:<\/p>\n<ol>\n<li>\u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0627\u0644\u0645\u0624\u0634\u0631:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *p;\r\n<\/pre>\n<p>\u064a\u0639\u0644\u0646 \u0639\u0646 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644\u0645\u0624\u0634\u0631 p \u0627\u0644\u0630\u064a \u0633\u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645\u0647 \u0644\u062a\u062e\u0632\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0639\u062f\u062f \u0635\u062d\u064a\u062d \u0645\u062e\u0635\u0635 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<li>\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">p = new int;\r\n<\/pre>\n<p>\u064a\u062e\u0635\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0639\u0644\u0649 \u0627\u0644\u0640heap \u0644\u062a\u062e\u0632\u064a\u0646 \u0639\u062f\u062f \u0635\u062d\u064a\u062d \u0648\u064a\u0639\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u0644\u0644\u0645\u0624\u0634\u0631 p.<\/li>\n<li>\u062a\u0639\u064a\u064a\u0646 \u0642\u064a\u0645\u0629:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">*p = 10;\r\n<\/pre>\n<p>\u064a\u062a\u0645 \u0625\u0644\u063a\u0627\u0621 \u0627\u0644\u0625\u0634\u0627\u0631\u0629 \u0625\u0644\u0649 \u0627\u0644\u0645\u0624\u0634\u0631 p \u0648\u062a\u0639\u064a\u064a\u0646 \u0627\u0644\u0642\u064a\u0645\u0629 10 \u0644\u0644\u0639\u062f\u062f \u0627\u0644\u0635\u062d\u064a\u062d \u0627\u0644\u0645\u062e\u0635\u0635 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0627\u0644\u0639\u0646\u0648\u0627\u0646:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cout &lt;&lt; p &lt;&lt; endl;\r\n<\/pre>\n<p>\u064a\u0637\u0628\u0639 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627. \u0647\u0630\u0627 \u0627\u0644\u0639\u0646\u0648\u0627\u0646 \u0645\u0648\u062c\u0648\u062f \u0641\u064a \u0627\u0644\u0640heap \u0648\u0642\u062f \u064a\u062e\u062a\u0644\u0641 \u0641\u064a \u0643\u0644 \u0645\u0631\u0629 \u064a\u062a\u0645 \u0641\u064a\u0647\u0627 \u062a\u0634\u063a\u064a\u0644 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c.<\/li>\n<li>\u0625\u0644\u063a\u0627\u0621 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">delete p;\r\n<\/pre>\n<p>\u0625\u0644\u063a\u0627\u0621 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u0645\u0633\u0628\u0642\u064b\u0627 \u0628\u0623\u062e\u0631\u0649 \u062c\u062f\u064a\u062f\u0629. \u0647\u0630\u0647 \u0627\u0644\u062e\u0637\u0648\u0629 \u0636\u0631\u0648\u0631\u064a\u0629 \u0644\u0645\u0646\u0639 \u062a\u0633\u0631\u0628 \u0627\u0644\u0630\u0627\u0643\u0631\u0629.<\/li>\n<\/ol>\n<p><strong>\u0645\u062b\u0627\u0644 3:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    \/\/ Declare two pointer variables\r\n    int *p1, *p2;\r\n\r\n    \/\/ Allocate memory for the first integer on the heap\r\n    p1 = new int;\r\n    *p1 = 10;\r\n\r\n    \/\/ Print the location of the pointer and the content of the allocated memory\r\n    cout &lt;&lt; &amp;p1 &lt;&lt; endl; \/\/ location of the pointer\r\n    cout &lt;&lt; \"Memory location \" &lt;&lt; p1 &lt;&lt; \"\\n\";\r\n    cout &lt;&lt; \" contains \" &lt;&lt; *p1 &lt;&lt; endl;\r\n\r\n    \/\/ Allocate memory for the second integer on the heap\r\n    p2 = new int;\r\n    *p2 = 10;\r\n\r\n    \/\/ Print the location of the second pointer and the content of the allocated memory\r\n    cout &lt;&lt; &amp;p2 &lt;&lt; endl; \/\/ location of the pointer\r\n    cout &lt;&lt; \"Memory location \" &lt;&lt; p2 &lt;&lt; \"\\n\" &lt;&lt; \" contains \" &lt;&lt; *p2 &lt;&lt; endl;\r\n\r\n    \/\/ Deallocate the dynamically allocated memory\r\n    delete p1;\r\n    delete p2;\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 \u0644\u0645\u062a\u063a\u064a\u0631\u064a\u0646 \u0635\u062d\u064a\u062d\u064a\u0646 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a. \u0648\u0641\u064a\u0645\u0627 \u064a\u0644\u064a \u0634\u0631\u062d \u0644\u0644\u0643\u0648\u062f:<\/p>\n<ol>\n<li>\u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0627\u0644\u0645\u0624\u0634\u0631:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *p1, *p2;\r\n<\/pre>\n<p>\u064a\u0639\u0644\u0646 \u0639\u0646 \u0645\u062a\u063a\u064a\u0631\u064a \u0627\u0644\u0645\u0624\u0634\u0631\u060c p1 \u0648p2\u060c \u0627\u0644\u0644\u0630\u064a\u0646 \u0633\u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645\u0647\u0645\u0627 \u0644\u062a\u062e\u0632\u064a\u0646 \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0623\u0639\u062f\u0627\u062f \u0627\u0644\u0635\u062d\u064a\u062d\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<li>\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 (p1):\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">p1 = new int;\r\n*p1 = 10;\r\n<\/pre>\n<p>\u064a\u062e\u0635\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0641\u064a \u0627\u0644\u0640heap \u0644\u0639\u062f\u062f \u0635\u062d\u064a\u062d \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 new\u060c \u0648\u064a\u0639\u064a\u0646 \u0627\u0644\u0639\u0646\u0648\u0627\u0646 \u0625\u0644\u0649 p1\u060c \u0648\u064a\u0639\u064a\u0646 \u0627\u0644\u0642\u064a\u0645\u0629 10 \u0644\u0644\u0639\u062f\u062f \u0627\u0644\u0635\u062d\u064a\u062d \u0627\u0644\u0645\u062e\u0635\u0635 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0627\u0644\u0645\u0639\u0644\u0648\u0645\u0627\u062a (p1):\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cout &lt;&lt; &amp;p1 &lt;&lt; endl; \/\/ location of the pointer\r\ncout &lt;&lt; \"Memory location \" &lt;&lt; p1 &lt;&lt; \"\\n\";\r\ncout &lt;&lt; \" contains \" &lt;&lt; *p1 &lt;&lt; endl;<\/pre>\n<p>\u064a\u0637\u0628\u0639 \u0645\u0648\u0642\u0639 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644\u0645\u0624\u0634\u0631 p1 \u0648\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062a\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647\u0627.<\/li>\n<li>\u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 (p2):\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">p2 = new int;\r\n*p2 = 10;\r\n<\/pre>\n<p>\u064a\u062e\u0635\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0641\u064a \u0627\u0644\u0640heap \u0644\u0639\u062f\u062f \u0635\u062d\u064a\u062d \u0622\u062e\u0631 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 new\u060c \u0648\u064a\u0639\u064a\u0646 \u0627\u0644\u0639\u0646\u0648\u0627\u0646 \u0644\u0640 p2\u060c \u0648\u064a\u0639\u064a\u0646 \u0627\u0644\u0642\u064a\u0645\u0629 10 \u0644\u0644\u0639\u062f\u062f \u0627\u0644\u0635\u062d\u064a\u062d \u0627\u0644\u0645\u062e\u0635\u0635 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0627\u0644\u0645\u0639\u0644\u0648\u0645\u0627\u062a (p2):\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cout &lt;&lt; &amp;p2 &lt;&lt; endl; \/\/ location of the pointer\r\ncout &lt;&lt; \"Memory location \" &lt;&lt; p2 &lt;&lt; \"\\n\" &lt;&lt; \" contains \" &lt;&lt; *p2 &lt;&lt; endl;\r\n<\/pre>\n<p>\u064a\u0637\u0628\u0639 \u0645\u0648\u0642\u0639 \u0645\u062a\u063a\u064a\u0631 \u0627\u0644\u0645\u0624\u0634\u0631 p2 \u0648\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062a\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647\u0627.<\/li>\n<li>\u0625\u0644\u063a\u0627\u0621 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">delete p1;\r\ndelete p2;\r\n<\/pre>\n<p>\u0625\u0644\u063a\u0627\u0621 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 delete \u0644\u062a\u062c\u0646\u0628 \u062a\u0633\u0631\u0628 \u0627\u0644\u0630\u0627\u0643\u0631\u0629.<\/li>\n<\/ol>\n<p><strong>\u0645\u062b\u0627\u0644 4:<br \/>\n<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nclass CRectangle \r\n{\r\n        int *width, *height;\r\n    public:\r\n        CRectangle(int, int); \/\/constructor\r\n        ~CRectangle(); \/\/destructor\r\n        int area()\r\n        {\r\n            return (*width * *height);\r\n        }\r\n};\r\nCRectangle::CRectangle(int a, int b)\r\n{\r\n    width = new int;\r\n    height = new int;\r\n    *width = a;\r\n    *height = b;\r\n}\r\nCRectangle::~CRectangle()\r\n{\r\n    delete width;\r\n    delete height;\r\n}\r\nint main()\r\n{\r\n    CRectangle rect(3, 4), rectb(5, 6);\r\n    cout &lt;&lt; \"rect area: \" &lt;&lt; rect.area() &lt;&lt; endl;\r\n    cout &lt;&lt; \"rectb area: \" &lt;&lt; rectb.area() &lt;&lt; endl;\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u062d\u062f\u062f \u0647\u0630\u0627 \u0627\u0644\u0631\u0645\u0632 \u0641\u0626\u0629 CRectangle \u0644\u0644\u0645\u0633\u062a\u0637\u064a\u0644\u0627\u062a \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 \u0644\u0644\u0639\u0631\u0636 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639. \u0625\u0644\u064a\u0643 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0643\u0648\u062f:<\/p>\n<ol>\n<li>\u062a\u0639\u0631\u064a\u0641 \u0627\u0644\u0641\u0626\u0629 (CRectangle):<br \/>\n\u062a\u0645\u062b\u0644 \u0627\u0644\u0641\u0626\u0629 CRectangle \u0645\u0633\u062a\u0637\u064a\u0644\u0627\u062a\u060c \u0645\u0639 \u062a\u062e\u0632\u064a\u0646 \u0639\u0631\u0636 \u0648\u0627\u0631\u062a\u0641\u0627\u0639 \u0627\u0644\u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u062e\u0627\u0635\u064a\u0646 \u0643\u0645\u0624\u0634\u0631\u0627\u062a \u0623\u0639\u062f\u0627\u062f \u0635\u062d\u064a\u062d\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629.<\/li>\n<li>\u0623\u062f\u0627\u0629 \u0627\u0644\u0628\u0646\u0627\u0621 Constructor (CRectangle::CRectangle):<br \/>\n\u064a\u062e\u0635\u0635 \u0627\u0644\u0640constructor  \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0644\u0639\u0631\u0636 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 new \u0648\u064a\u0642\u0648\u0645 \u0628\u062a\u0647\u064a\u0626\u062a\u0647\u0645 \u0628\u0627\u0644\u0642\u064a\u0645 \u0627\u0644\u0645\u0642\u062f\u0645\u0629.<\/li>\n<li>\u0623\u062f\u0627\u0629 \u0627\u0644\u0647\u062f\u0645 Destructor (CRectangle::~CRectangle):<br \/>\n\u064a\u0642\u0648\u0645 \u0627\u0644\u0640destructor  \u0628\u0625\u0644\u063a\u0627\u0621 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0644\u0639\u0631\u0636 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 delete.<\/li>\n<li>\u062f\u0627\u0644\u0629 \u0627\u0644\u0639\u0636\u0648 (area):<br \/>\n\u062a\u0642\u0648\u0645 \u062f\u0627\u0644\u0629 area \u0628\u062d\u0633\u0627\u0628 \u0645\u0633\u0627\u062d\u0629 \u0627\u0644\u0645\u0633\u062a\u0637\u064a\u0644 \u0648\u0625\u0631\u062c\u0627\u0639\u0647\u0627 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0642\u064a\u0645 \u0627\u0644\u0645\u062e\u0632\u0646\u0629 \u0641\u064a \u0627\u0644\u0639\u0631\u0636 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639.<\/li>\n<li>\u0627\u0644\u062f\u0627\u0644\u0629 \u0627\u0644\u0631\u0626\u064a\u0633\u0629 main:<br \/>\n\u064a\u0646\u0634\u0626 \u0645\u062b\u064a\u0644\u0627\u062a CRectangle (rect and rectb) \u0645\u0639 \u062a\u062e\u0635\u064a\u0635 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u0629 \u0644\u0644\u0639\u0631\u0636 \u0648\u0627\u0644\u0627\u0631\u062a\u0641\u0627\u0639.<br \/>\n\u064a\u0633\u062a\u062f\u0639\u064a \u062f\u0627\u0644\u0629 area \u0644\u062d\u0633\u0627\u0628 \u0648\u0639\u0631\u0636 \u0645\u0633\u0627\u062d\u0629 \u0643\u0644 \u0645\u0633\u062a\u0637\u064a\u0644.<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 \u0623\u062f\u0648\u0627\u062a \u0627\u0644\u062a\u062f\u0645\u064a\u0631 \u062a\u0644\u0642\u0627\u0626\u064a\u064b\u0627 \u0639\u0646\u062f\u0645\u0627 \u062a\u062e\u0631\u062c (rect and rectb) \u0639\u0646 \u0627\u0644\u0646\u0637\u0627\u0642\u060c \u0645\u0645\u0627 \u064a\u0624\u062f\u064a \u0625\u0644\u0649 \u062a\u062d\u0631\u064a\u0631 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0635\u0635\u0629 \u062f\u064a\u0646\u0627\u0645\u064a\u0643\u064a\u064b\u0627.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>In object-oriented programming (OOP) with C++, pointers play a crucial role in managing memory and accessing objects dynamically. Here&#8217;s a brief explanation of pointers in the context of OOP in C++: Definition: A pointer is a variable that holds the memory address of another variable. In C++, pointers can be used to store addresses of [&hellip;]<\/p>","protected":false},"author":3,"featured_media":0,"parent":4291,"menu_order":45,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-10460","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/comments?post=10460"}],"version-history":[{"count":8,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10460\/revisions"}],"predecessor-version":[{"id":10468,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10460\/revisions\/10468"}],"up":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/4291"}],"wp:attachment":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/media?parent=10460"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/doc_tag?post=10460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}