{"id":111,"date":"2026-05-20T12:12:58","date_gmt":"2026-05-20T12:12:58","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=111"},"modified":"2026-05-22T10:41:48","modified_gmt":"2026-05-22T10:41:48","slug":"pointers-with-arrays","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=pointers-with-arrays","title":{"rendered":"Pointers with Arrays"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Pointers and arrays are closely related in C++. The name of an array acts like a pointer to its first element, which makes array handling more efficient and flexible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Pointers with Arrays?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When an array is created, the array name stores the address of the first element. A pointer can be used to access and manipulate array elements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Pointers with Arrays?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pointers with arrays are useful because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allow efficient array traversal<\/li>\n\n\n\n<li>Improve performance<\/li>\n\n\n\n<li>Simplify memory handling<\/li>\n\n\n\n<li>Support dynamic programming techniques<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Array Name as Pointer<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int arr&#91;5] = {10, 20, 30, 40, 50};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>arr<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">stores the address of the first element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Program<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int arr&#91;3] = {10, 20, 30};<br><br>    cout &lt;&lt; arr &lt;&lt; endl;<br>    cout &lt;&lt; &amp;arr&#91;0] &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both statements print the same address.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using Pointer with Array<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int arr&#91;3] = {10, 20, 30};<br><br>    int *ptr = arr;<br><br>    cout &lt;&lt; *ptr &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>10<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Array Elements Using Pointer<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int arr&#91;3] = {10, 20, 30};<br><br>    int *ptr = arr;<br><br>    cout &lt;&lt; *(ptr + 0) &lt;&lt; endl;<br>    cout &lt;&lt; *(ptr + 1) &lt;&lt; endl;<br>    cout &lt;&lt; *(ptr + 2) &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>10<br>20<br>30<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Pointer Arithmetic with Arrays<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pointers move according to the size of the data type.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ptr++;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This moves the pointer to the next array element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Traversing Array Using Pointer<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int arr&#91;5] = {1, 2, 3, 4, 5};<br><br>    int *ptr = arr;<br><br>    for (int i = 0; i &lt; 5; i++) {<br><br>        cout &lt;&lt; *(ptr + i) &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Modifying Array Elements Using Pointer<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br><br>    int arr&#91;3] = {10, 20, 30};<br><br>    int *ptr = arr;<br><br>    *(ptr + 1) = 100;<br><br>    cout &lt;&lt; arr&#91;1];<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>100<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Difference Between Array and Pointer<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Array<\/th><th>Pointer<\/th><\/tr><\/thead><tbody><tr><td>Fixed memory block<\/td><td>Variable storing address<\/td><\/tr><tr><td>Cannot be reassigned<\/td><td>Can point to different locations<\/td><\/tr><tr><td>Stores multiple elements<\/td><td>Stores memory address<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Important Points<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Array name acts like a constant pointer<\/li>\n\n\n\n<li>Pointers can access array elements efficiently<\/li>\n\n\n\n<li>Arrays and pointers are closely connected<\/li>\n\n\n\n<li>Pointer arithmetic is commonly used with arrays<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of Using Pointers with Arrays<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Faster access to elements<\/li>\n\n\n\n<li>Efficient memory usage<\/li>\n\n\n\n<li>Useful in dynamic arrays<\/li>\n\n\n\n<li>Supports advanced data structures<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Pointers with Arrays are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">They are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Improve array processing efficiency<\/li>\n\n\n\n<li>Support dynamic memory management<\/li>\n\n\n\n<li>Are used in low-level programming<\/li>\n\n\n\n<li>Help understand memory concepts deeply<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Real-Life Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Think of an apartment building:<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779446534298\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Array elements are apartments<\/li>\n\n\n\n<li>Pointer acts like a map pointing to apartment locations<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Using pointer arithmetic is like moving from one apartment to the next.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pointers with arrays in C++ provide efficient and flexible ways to access and manipulate array data. Understanding this relationship is essential for advanced programming, memory management, and high-performance applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/cpp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate C++ > Pointers > Pointers with Arrays<\/span><\/span><\/div>","protected":false},"menu_order":32,"template":"","class_list":["post-111","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pointers with Arrays - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\/modifying elements using pointers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pointers with Arrays - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\/modifying elements using pointers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn C++Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T10:41:48+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?lesson=pointers-with-arrays\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Pointers with Arrays - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-20T12:12:58+00:00\",\"dateModified\":\"2026-05-22T10:41:48+00:00\",\"description\":\"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\\\/modifying elements using pointers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/cpp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate C++ > Pointers > Pointers with Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/\",\"name\":\"Learn C++Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pointers with Arrays - Learn C++Language with GiGz.PK","description":"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\/modifying elements using pointers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Pointers with Arrays - Learn C++Language with GiGz.PK","og_description":"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\/modifying elements using pointers.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T10:41:48+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/cpp\/?lesson=pointers-with-arrays","url":"https:\/\/gigz.pk\/","name":"Pointers with Arrays - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-20T12:12:58+00:00","dateModified":"2026-05-22T10:41:48+00:00","description":"Learn C++ pointers with arrays, including array traversal, pointer arithmetic, and accessing\/modifying elements using pointers.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/cpp"},{"@type":"ListItem","position":2,"name":"Intermediate C++ > Pointers > Pointers with Arrays"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/cpp\/#website","url":"https:\/\/gigz.pk\/cpp\/","name":"Learn C++Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/cpp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}