{"id":10469,"date":"2024-02-03T21:46:44","date_gmt":"2024-02-03T21:46:44","guid":{"rendered":"https:\/\/adelnasim.com\/docs\/courses\/oop\/array-of-object-and-pointers-to-objects\/"},"modified":"2024-04-07T01:19:44","modified_gmt":"2024-04-07T01:19:44","slug":"array-of-object-and-pointers-to-objects","status":"publish","type":"docs","link":"https:\/\/adelnasim.com\/ar\/docs\/courses\/oop\/array-of-object-and-pointers-to-objects\/","title":{"rendered":"\u0645\u0635\u0641\u0648\u0641\u0629 \u0645\u0646 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a object \u0648\u0645\u0624\u0634\u0631\u0627\u062a \u0644\u0644\u0643\u0627\u0626\u0646\u0627\u062a objects"},"content":{"rendered":"<p>\u0641\u064a \u0639\u0627\u0644\u0645 \u0627\u0644\u0628\u0631\u0645\u062c\u0629 \u0627\u0644\u0643\u0627\u0626\u0646\u064a\u0629 (OOP) \u0645\u0639 \u0644\u063a\u0629 C++\u060c \u062a\u0639\u062f \u0625\u062f\u0627\u0631\u0629 \u0643\u0627\u0626\u0646\u0627\u062a \u0645\u062a\u0639\u062f\u062f\u0629 \u0628\u0643\u0641\u0627\u0621\u0629 \u0623\u0645\u0631\u064b\u0627 \u0628\u0627\u0644\u063a \u0627\u0644\u0623\u0647\u0645\u064a\u0629. \u0647\u0646\u0627\u0643 \u0645\u0641\u0647\u0648\u0645\u0627\u0646 \u0642\u0648\u064a\u0627\u0646 \u064a\u0633\u0627\u0639\u062f\u0627\u0646 \u0641\u064a \u062a\u062d\u0642\u064a\u0642 \u0630\u0644\u0643 <strong>\u0645\u0635\u0641\u0648\u0641\u0629 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a Arrays of Objects<\/strong> \u0648 <strong>\u0645\u0624\u0634\u0631\u0627\u062a \u0644\u0644\u0643\u0627\u0626\u0646\u0627\u062a Pointers to Objects<\/strong>. \u0633\u0646\u0648\u0636\u062d \u0643\u0644\u0627 \u0627\u0644\u0645\u0641\u0647\u0648\u0645\u064a\u0646 \u0648\u0643\u064a\u0641\u064a\u0629 \u062a\u0648\u0638\u064a\u0641\u0647\u0645\u0627 \u0641\u064a \u0644\u063a\u0629 C++.<\/p>\n<p><strong>\u0645\u062b\u0627\u0644 1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\nint main()\r\n{\r\n    int arr[5] = {10, 50, 40, 77, 33};\r\n\r\n    \/\/ Printing the memory address of the array (address of the first element)\r\n    cout &lt;&lt; arr &lt;&lt; endl;\r\n\r\n    \/\/ Printing the value at the first element of the array\r\n    cout &lt;&lt; *arr &lt;&lt; endl;\r\n\r\n    \/\/ Printing the memory address of the second element of the array\r\n    cout &lt;&lt; arr + 1 &lt;&lt; endl;\r\n\r\n    \/\/ Printing the memory address of the last element of the array\r\n    cout &lt;&lt; arr + 4 &lt;&lt; endl;\r\n\r\n    \/\/ Printing the value at the last element of the array\r\n    cout &lt;&lt; *(arr + 4) &lt;&lt; endl;\r\n    \r\n    \/\/ Using a loop to print all elements of the array using pointer arithmetic\r\n    for (size_t i = 0; i &lt; 5; i++)\r\n    {\r\n        cout&lt;&lt; *(arr + i) &lt;&lt; endl;\r\n    }\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0645\u0639 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0627\u062a.<\/p>\n<p>\u0633\u062a\u0639\u0631\u0636 \u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a \u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0648\u0642\u064a\u0645\u0647\u0627 \u0648\u0639\u0646\u0627\u0635\u0631 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629 \u0628\u0646\u0627\u0621\u064b \u0639\u0644\u0649 \u062d\u0633\u0627\u0628 \u0627\u0644\u0645\u0624\u0634\u0631 \u0648\u062a\u0643\u0631\u0627\u0631\u0627\u062a \u0627\u0644\u062d\u0644\u0642\u0629.<\/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\nint main()\r\n{\r\n    int arr[5] = {10, 50, 40, 77, 33};\r\n    int *p;\r\n    p = arr;\r\n    for (size_t i = 0; i &lt; 5; i++)\r\n    {\r\n        cout &lt;&lt; *p &lt;&lt; endl;\r\n        p++;\r\n    }\r\n\r\n    return 0;\r\n}<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0628\u0631\u0646\u0627\u0645\u062c C++ \u0647\u0630\u0627 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631 \u0644\u0644\u062a\u0643\u0631\u0627\u0631 \u0639\u0628\u0631 \u0645\u0635\u0641\u0648\u0641\u0629.<\/p>\n<p>\u0633\u062a\u0639\u0631\u0636 \u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a \u0642\u064a\u0645 \u0643\u0644 \u0639\u0646\u0635\u0631 \u0641\u064a \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629\u060c \u0645\u0637\u0628\u0648\u0639\u064b\u0627 \u0648\u0627\u062d\u062f\u064b\u0627 \u062a\u0644\u0648 \u0627\u0644\u0622\u062e\u0631\u060c \u062d\u064a\u062b \u064a\u062a\u0645 \u0632\u064a\u0627\u062f\u0629 \u0627\u0644\u0645\u0624\u0634\u0631 p \u062f\u0627\u062e\u0644 \u0627\u0644\u062d\u0644\u0642\u0629.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">10\r\n50\r\n40\r\n77\r\n33\r\n<\/pre>\n<p>\u0645\u0644\u062d\u0648\u0638\u0629 !<\/p>\n<ul>\n<li>\u064a\u062a\u0645 \u062a\u0639\u064a\u064a\u0646 \u0627\u0644\u0645\u0624\u0634\u0631 p \u0645\u0628\u062f\u0626\u064a\u064b\u0627 \u0639\u0644\u0649 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0639\u0646\u0635\u0631 \u0627\u0644\u0623\u0648\u0644 \u0641\u064a \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629.<\/li>\n<li>\u0632\u064a\u0627\u062f\u0629 \u0627\u0644\u0645\u0624\u0634\u0631 (p++) \u064a\u062c\u0639\u0644\u0647 \u064a\u0634\u064a\u0631 \u0625\u0644\u0649 \u0627\u0644\u0639\u0646\u0635\u0631 \u0627\u0644\u062a\u0627\u0644\u064a \u0641\u064a \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629.<\/li>\n<li>\u064a\u0648\u0641\u0631 \u0647\u0630\u0627 \u0627\u0644\u0623\u0633\u0644\u0648\u0628 \u0637\u0631\u064a\u0642\u0629 \u0628\u062f\u064a\u0644\u0629 \u0644\u0644\u062a\u0643\u0631\u0627\u0631 \u0639\u0628\u0631 \u0639\u0646\u0627\u0635\u0631 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a.<\/li>\n<\/ul>\n<p><strong>\u0645\u062b\u0627\u0644 3:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt;\r\n#include &lt;cstring&gt;\r\nusing namespace std;\r\nclass Student\r\n{\r\n        char name[20];\r\n        int ID;\r\n    public:\r\n        Student() \/\/empty constructor\r\n        {\r\n            cout &lt;&lt; \"empty\\n\";\r\n            strcpy(name, \"No name\");\r\n            ID = 0;\r\n        }\r\n        Student(char n[], int id) \/\/constructor overloading\r\n        {\r\n            cout &lt;&lt; \"parameterize\\n\";\r\n            strcpy(name, n);\r\n            ID = id;\r\n        }\r\n        void print(void)\r\n        {\r\n            cout &lt;&lt; name &lt;&lt; \"\\t\" &lt;&lt; ID &lt;&lt; endl;\r\n        }\r\n};\r\nint main()\r\n{\r\n    Student S1(\"Ali\", 123), S2(\"Ahmad\", 456);\r\n    Student arr[3];\r\n    for (int i = 0; i &lt; 3; i++)\r\n        arr[i].print();\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u0648\u0636\u062d \u0647\u0630\u0627 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c \u0627\u0633\u062a\u062e\u062f\u0627\u0645 constructor overloading \u0648default constructors \u0641\u064a \u0627\u0644\u0640class. \u062f\u0639\u0648\u0646\u0627 \u0646\u062d\u0644\u0644 \u0627\u0644\u0643\u0648\u062f:<\/p>\n<ol>\n<li>Class Student:<br \/>\n\u064a\u062d\u062f\u062f class \u064a\u0633\u0645\u0649 \u0627\u0644\u0637\u0627\u0644\u0628 \u0645\u0639 \u0627\u0633\u0645 \u0648\u0645\u0639\u0631\u0641 \u0623\u0639\u0636\u0627\u0621 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a \u0627\u0644\u062e\u0627\u0635\u0629.<br \/>\n\u064a\u062d\u062a\u0648\u064a \u0639\u0644\u0649 constructors \u0627\u062b\u0646\u064a\u0646: constructor \u0641\u0627\u0631\u063a \u0648parameterized constructor.<br \/>\n\u064a\u0648\u0641\u0631 \u062f\u0627\u0644\u0629 \u0639\u0636\u0648 \u0648\u0647\u064a \u062f\u0627\u0644\u0629 \u0627\u0644\u0637\u0628\u0627\u0639\u0629 \u0644\u0639\u0631\u0636 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0627\u0644\u0628.<\/li>\n<li>Empty Constructor:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Student()\r\n{\r\n    cout &lt;&lt; \"empty\\n\";\r\n    strcpy(name, \"No name\");\r\n    ID = 0;\r\n}\r\n<\/pre>\n<p>\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0627\u0633\u0645 \u0628\u0640 \"No name\" \u0648\u0627\u0644\u0645\u0639\u0631\u0641 \u0628\u0640 0.<br \/>\n\u0637\u0628\u0627\u0639\u0629 \"empty\" \u0639\u0646\u062f \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0647\u0630\u0627 \u0627\u0644\u0640constructor.<\/li>\n<li>Constructor Overloading:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Student(char n[], int id)\r\n{\r\n    cout &lt;&lt; \"parameterize\\n\";\r\n    strcpy(name, n);\r\n    ID = id;\r\n}\r\n<\/pre>\n<p>\u062a\u0647\u064a\u0626\u0629 \u0627\u0644\u0627\u0633\u0645 \u0648\u0627\u0644\u0645\u0639\u0631\u0641 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0640arguments \u0627\u0644\u0645\u062a\u0648\u0641\u0631\u0629.<br \/>\n\u0637\u0628\u0627\u0639\u0629 \"parameterize\" \u0639\u0646\u062f \u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0647\u0630\u0627 \u0627\u0644\u0640constructor.<\/li>\n<li>print() Function:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void print(void)\r\n{\r\n    cout &lt;&lt; name &lt;&lt; \"\\t\" &lt;&lt; ID &lt;&lt; endl;\r\n}\r\n\r\n<\/pre>\n<p>\u0637\u0628\u0627\u0639\u0629 \u0627\u0633\u0645 \u0627\u0644\u0637\u0627\u0644\u0628 \u0648\u0647\u0648\u064a\u062a\u0647.<\/li>\n<li>\u0625\u0646\u0634\u0627\u0621 \u0643\u0627\u0626\u0646\u0627\u062a:<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0643\u0627\u0626\u0646\u064a\u0646 S1 \u0648S2 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 parameterized constructor\u060c \u0645\u0639 \u0639\u0631\u0636 \"parameterize\" \u0644\u0643\u0644 \u0643\u0627\u0626\u0646.<br \/>\n\u064a\u062a\u0645 \u0625\u0646\u0634\u0627\u0621 \u0645\u0635\u0641\u0648\u0641\u0629 \u0645\u0646 \u0643\u0627\u0626\u0646\u0627\u062a \u0627\u0644\u0637\u0627\u0644\u0628 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645  default constructor\u060c \u0645\u0639 \u0639\u0631\u0636 \"empty\" \u0644\u0643\u0644 \u0643\u0627\u0626\u0646.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u062a\u0641\u0627\u0635\u064a\u0644 \u0627\u0644\u0637\u0627\u0644\u0628:<br \/>\n\u064a\u062a\u0645 \u0627\u0633\u062a\u062f\u0639\u0627\u0621 \u0627\u0644\u062f\u0627\u0644\u0629 print() \u0644\u0643\u0644 \u0643\u0627\u0626\u0646 \u0641\u064a \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629 \u0644\u0639\u0631\u0636 \u062a\u0641\u0627\u0635\u064a\u0644\u0647.<\/li>\n<\/ol>\n<p>\u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a:<br \/>\n\u0633\u062a\u0639\u0631\u0636 \u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a \u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u0640constructor \u0648\u062a\u0641\u0627\u0635\u064a\u0644 \u0643\u0644 \u0637\u0627\u0644\u0628 \u0641\u064a \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>In the world of object-oriented programming (OOP) with C++, managing multiple objects efficiently is crucial. Two powerful concepts that help achieve this are Arrays of Objects and Pointers to Objects. This documentation will provide a clear understanding of both concepts and how they can be employed in C++. Example 1: #include &lt;iostream&gt; using namespace std; [&hellip;]<\/p>","protected":false},"author":3,"featured_media":0,"parent":4291,"menu_order":46,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-10469","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10469","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=10469"}],"version-history":[{"count":7,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10469\/revisions"}],"predecessor-version":[{"id":10624,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10469\/revisions\/10624"}],"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=10469"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/doc_tag?post=10469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}