{"id":10087,"date":"2023-11-09T12:23:51","date_gmt":"2023-11-09T12:23:51","guid":{"rendered":"https:\/\/adelnasim.com\/docs\/courses\/cpp-tutorial\/pointer\/"},"modified":"2024-04-07T01:19:37","modified_gmt":"2024-04-07T01:19:37","slug":"pointer","status":"publish","type":"docs","link":"https:\/\/adelnasim.com\/ar\/docs\/courses\/cpp-tutorial\/pointer\/","title":{"rendered":"\u0627\u0644\u0645\u0624\u0634\u0631 - Pointer"},"content":{"rendered":"<p>\u0641\u064a \u0644\u063a\u0629 C++\u060c \u0627\u0644\u0645\u0624\u0634\u0631 \u0647\u0648 \u0645\u062a\u063a\u064a\u0631 \u064a\u0642\u0648\u0645 \u0628\u062a\u062e\u0632\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0645\u062a\u063a\u064a\u0631 \u0622\u062e\u0631. \u062a\u0648\u0641\u0631 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0622\u0644\u064a\u0629 \u0642\u0648\u064a\u0629 \u0644\u0644\u0639\u0645\u0644 \u0645\u0639 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0648\u0647\u064a\u0627\u0643\u0644 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a. \u0625\u0646\u0647\u0627 \u062a\u0633\u0645\u062d \u0628\u0627\u0644\u0645\u0639\u0627\u0644\u062c\u0629 \u0627\u0644\u0645\u0628\u0627\u0634\u0631\u0629 \u0644\u0639\u0646\u0627\u0648\u064a\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0648\u062a\u0645\u0643\u0646 \u0645\u0646 \u0625\u062f\u0627\u0631\u0629 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0628\u0643\u0641\u0627\u0621\u0629.<\/p>\n<h2>\u0625\u0639\u0644\u0627\u0646 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a<\/h2>\n<p>\u0644\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0645\u0624\u0634\u0631\u060c \u064a\u0645\u0643\u0646\u0643 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0646\u0648\u0639 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a \u0645\u062a\u0628\u0648\u0639\u064b\u0627 \u0628\u0627\u0644\u0639\u0644\u0627\u0645\u0629 \u0627\u0644\u0646\u062c\u0645\u064a\u0629 (*) \u0648\u0627\u0633\u0645 \u0627\u0644\u0645\u0624\u0634\u0631. \u0639\u0644\u0649 \u0633\u0628\u064a\u0644 \u0627\u0644\u0645\u062b\u0627\u0644:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *ptr; \/\/ Declares a pointer to an integer\r\ndouble *dblPtr; \/\/ Declares a pointer to a double<\/pre>\n<h2>\u062a\u0641\u0639\u064a\u0644 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a<\/h2>\n<p>\u064a\u062c\u0628 \u062a\u0641\u0639\u064a\u0644 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a \u0642\u0628\u0644 \u0627\u0644\u0627\u0633\u062a\u062e\u062f\u0627\u0645. \u064a\u0645\u0643\u0646\u0643 \u062a\u0641\u0639\u064a\u0644 \u0627\u0644\u0645\u0624\u0634\u0631 \u0639\u0646 \u0637\u0631\u064a\u0642 \u062a\u0639\u064a\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0645\u062a\u063a\u064a\u0631 \u0644\u0647. \u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0640operator (&amp;) \u0644\u0644\u062d\u0635\u0648\u0644 \u0639\u0644\u0649 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0644\u0645\u062a\u063a\u064a\u0631.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int num = 10;\r\nint *ptr = &amp;num; \/\/ Initializes ptr with the address of num<\/pre>\n<h2>\u0639\u062f\u0645 \u0645\u0631\u062c\u0639\u064a\u0629 \u0627\u0644\u0645\u0624\u0634\u0631\u0627\u062a Dereferencing Pointers<\/h2>\n<p>Dereferencing a pointer \u0625\u0644\u0649 \u0627\u0644\u0645\u0624\u0634\u0631 \u064a\u0639\u0646\u064a \u0627\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u0649 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u062e\u0632\u0646\u0629 \u0641\u064a \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0630\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647. \u064a\u062a\u0645 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0627\u0645\u0644 \u0627\u0644\u0640derefrencing (*) \u0644\u0647\u0630\u0627 \u0627\u0644\u063a\u0631\u0636.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int num = 10;\r\nint *ptr = &amp;num;\r\n\r\ncout &lt;&lt; *ptr; \/\/ Prints the value stored at the address pointed by ptr\r\n<\/pre>\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\n\r\nint main() {\r\n    \/\/ Declaration of a pointer to an integer\r\n    int *ptr;\r\n\r\n    \/\/ Declaration and initialization of an integer variable\r\n    int val = 5;\r\n\r\n    \/\/ Assigning the address of 'val' to the pointer 'ptr'\r\n    ptr = &amp;val;\r\n\r\n    \/\/ Printing the address stored in the pointer\r\n    cout &lt;&lt; ptr &lt;&lt; endl;\r\n\r\n    \/\/ Printing the value stored at the address pointed by 'ptr'\r\n    cout &lt;&lt; *ptr &lt;&lt; endl;\r\n\r\n    \/\/ Return 0 to indicate successful execution\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u064a\u0639\u0644\u0646 \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0639\u0646 \u0645\u0624\u0634\u0631\u060c \u0648\u064a\u0642\u0648\u0645 \u0628\u062a\u0641\u0639\u064a\u0644 \u0645\u062a\u063a\u064a\u0631 \u0639\u062f\u062f \u0635\u062d\u064a\u062d\u060c \u0648\u064a\u0639\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0647\u0630\u0627 \u0627\u0644\u0645\u062a\u063a\u064a\u0631 \u0644\u0644\u0645\u0624\u0634\u0631\u060c \u062b\u0645 \u064a\u0637\u0628\u0639 \u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0624\u0634\u0631 (\u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629) \u0648\u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u062a\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647\u0627.<\/p>\n<p>\u0627\u0644\u0646\u0642\u0627\u0637 \u0627\u0644\u0631\u0626\u064a\u0633\u064a\u0629:<\/p>\n<ol>\n<li>\u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0639\u0646 \u0627\u0644\u0645\u0624\u0634\u0631:<br \/>\nint *ptr;: \u064a\u0639\u0644\u0646 \u0639\u0646 \u0645\u0624\u0634\u0631 \u0644\u0639\u062f\u062f \u0635\u062d\u064a\u062d. \u0647\u0630\u0627 \u0627\u0644\u0645\u0624\u0634\u0631 \u063a\u064a\u0631 \u0645\u0641\u0639\u0644 \u062d\u0627\u0644\u064a\u064b\u0627.<\/li>\n<li>\u0627\u0644\u0625\u0639\u0644\u0627\u0646 \u0648\u062a\u0641\u0639\u064a\u0644 \u0627\u0644\u0645\u062a\u063a\u064a\u0631:<br \/>\nint val = 5;: \u064a\u0639\u0644\u0646 \u0639\u0646 \u0645\u062a\u063a\u064a\u0631 \u0639\u062f\u062f \u0635\u062d\u064a\u062d \u064a\u0633\u0645\u0649 val \u0648\u064a\u0642\u0648\u0645 \u0628\u062a\u0641\u0639\u064a\u0644\u0647 \u0648\u0625\u0639\u0637\u0627\u0624\u0647 \u0627\u0644\u0642\u064a\u0645\u0629 5.<\/li>\n<li>\u062a\u0639\u064a\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0644\u0644\u0645\u0624\u0634\u0631:<br \/>\nptr = &amp;val;: \u064a\u0639\u064a\u0646 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0644\u0644\u0645\u062a\u063a\u064a\u0631 val \u0644\u0644\u0645\u0624\u0634\u0631 ptr. \u0627\u0644\u0622\u0646 \"\u064a\u0634\u064a\u0631\" ptr \u0625\u0644\u0649 \u0645\u0648\u0642\u0639 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u062e\u0627\u0635 \u0628\u0640 val.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0624\u0634\u0631 (\u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629):<br \/>\ncout &lt;&lt; ptr &lt;&lt; endl;: \u064a\u0637\u0628\u0639 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0632\u0646 \u0641\u064a \u0627\u0644\u0645\u0624\u0634\u0631 ptr. \u064a\u062a\u0645 \u062a\u0645\u062b\u064a\u0644 \u0627\u0644\u0639\u0646\u0648\u0627\u0646 \u0639\u0627\u062f\u0629\u064b \u0628\u062a\u0646\u0633\u064a\u0642 hexadecimal.<\/li>\n<li>\u0637\u0628\u0627\u0639\u0629 \u0627\u0644\u0642\u064a\u0645\u0629 \u0639\u0644\u0649 \u0627\u0644\u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0645\u0634\u0627\u0631 \u0625\u0644\u064a\u0647 \u0628\u0627\u0644\u0645\u0624\u0634\u0631:<br \/>\ncout &lt;&lt; *ptr &lt;&lt; endl;: \u064a\u0633\u062a\u062e\u062f\u0645 \u0639\u0627\u0645\u0644 \u0627\u0644\u0640dereference (*) \u0644\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u0649 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u062e\u0632\u0646\u0629 \u0641\u064a \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u0634\u0627\u0631 \u0625\u0644\u064a\u0647 \u0628\u0648\u0627\u0633\u0637\u0629 ptr. \u0648\u064a\u0637\u0628\u0639 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u062e\u0632\u0646\u0629 \u0641\u064a \u0627\u0644\u0645\u062a\u063a\u064a\u0631 val.<\/li>\n<\/ol>\n<p>\u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a:<br \/>\n\u0625\u0630\u0627 \u0642\u0645\u062a \u0628\u062a\u0634\u063a\u064a\u0644 \u0647\u0630\u0627 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c\u060c \u0641\u0625\u0646 \u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a \u0633\u062a\u0643\u0648\u0646 \u0643\u0645\u0627 \u064a\u0644\u064a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">0x7ffee3c86a4c   \/\/ The memory address (this will vary on each run)\r\n5                \/\/ The value stored at the memory address\r\n<\/pre>\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 *p;\r\n    int v = 9;\r\n    p = &amp;v;\r\n    cout &lt;&lt; *p &lt;&lt; endl;\r\n    return 0;\r\n}<\/pre>\n<p>\u064a\u0637\u0628\u0639 \u0647\u0630\u0627 \u0627\u0644\u0643\u0648\u062f \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u062a\u064a \u064a\u0634\u064a\u0631 \u0625\u0644\u064a\u0647\u0627 \u0627\u0644\u0645\u0624\u0634\u0631 p \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u062a\u0639\u0628\u064a\u0631\u0627\u062a &amp;*p.<\/p>\n<p>cout &lt;&lt; &amp;*p &lt;&lt; endl;: \u064a\u0633\u062a\u062e\u062f\u0645 \u0639\u0627\u0645\u0644 \u0627\u0644\u0640dereference (*) \u0644\u0644\u0648\u0635\u0648\u0644 \u0625\u0644\u0649 \u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u062e\u0632\u0646\u0629 \u0641\u064a \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u0634\u0627\u0631 \u0625\u0644\u064a\u0647 \u0628\u0640 p. \u062b\u0645 \u064a\u0623\u062e\u0630 \u0639\u0627\u0645\u0644 \u0627\u0644\u062a\u0634\u063a\u064a\u0644 &amp; \u0639\u0646\u0648\u0627\u0646 \u0647\u0630\u0647 \u0627\u0644\u0642\u064a\u0645\u0629. \u0628\u0634\u0643\u0644 \u0623\u0633\u0627\u0633\u064a\u060c &amp;*p \u064a\u0639\u0627\u062f\u0644 p \u0641\u0642\u0637\u060c \u0644\u0630\u0644\u0643 \u064a\u0637\u0628\u0639 \u0647\u0630\u0627 \u0627\u0644\u0633\u0637\u0631 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0630\u0627\u0643\u0631\u0629 \u0627\u0644\u0645\u062e\u0632\u0646 \u0641\u064a \u0627\u0644\u0645\u0624\u0634\u0631 p.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>In C++, a pointer is a variable that stores the memory address of another variable. Pointers provide a powerful mechanism for working with memory and data structures. They allow direct manipulation of memory addresses and enable efficient memory management. Declaring Pointers To declare a pointer, you use the data type followed by an asterisk (*) [&hellip;]<\/p>","protected":false},"author":3,"featured_media":0,"parent":2744,"menu_order":35,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-10087","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10087","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=10087"}],"version-history":[{"count":6,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10087\/revisions"}],"predecessor-version":[{"id":10093,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/10087\/revisions\/10093"}],"up":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/2744"}],"wp:attachment":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/media?parent=10087"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/doc_tag?post=10087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}