{"id":97,"date":"2026-05-20T11:36:03","date_gmt":"2026-05-20T11:36:03","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=97"},"modified":"2026-05-22T08:18:34","modified_gmt":"2026-05-22T08:18:34","slug":"one-dimensional-arrays","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=one-dimensional-arrays","title":{"rendered":"One-Dimensional Arrays"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One-dimensional arrays in C++ are used to store multiple values of the same data type in a single variable. They help organize data efficiently and make programs easier to manage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a One-Dimensional Array?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A one-dimensional array is a collection of elements stored in a single row of memory locations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each element in the array is accessed using an index number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Arrays?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Arrays are useful because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store multiple values in one variable<\/li>\n\n\n\n<li>Reduce the need for many separate variables<\/li>\n\n\n\n<li>Make data handling easier<\/li>\n\n\n\n<li>Improve code organization<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of One-Dimensional Array<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>data_type array_name&#91;size];<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Array Declaration<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int numbers&#91;5];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates an array named <code>numbers<\/code> that can store 5 integer values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initializing an Array<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int numbers&#91;5] = {10, 20, 30, 40, 50};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Array Elements<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Array elements are accessed using index numbers.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First element index = 0<\/li>\n\n\n\n<li>Second element index = 1<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>cout &lt;&lt; numbers&#91;0];<br>cout &lt;&lt; numbers&#91;2];<\/code><\/pre>\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 numbers&#91;5] = {10, 20, 30, 40, 50};<br><br>    cout &lt;&lt; numbers&#91;0] &lt;&lt; endl;<br>    cout &lt;&lt; numbers&#91;1] &lt;&lt; endl;<br>    cout &lt;&lt; numbers&#91;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\">Using Loop with Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Loops are commonly used to access all array elements.<\/p>\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 numbers&#91;5] = {1, 2, 3, 4, 5};<br><br>    for (int i = 0; i &lt; 5; i++) {<br>        cout &lt;&lt; numbers&#91;i] &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Taking User Input in 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 marks&#91;3];<br><br>    for (int i = 0; i &lt; 3; i++) {<br>        cin &gt;&gt; marks&#91;i];<br>    }<br><br>    for (int i = 0; i &lt; 3; i++) {<br>        cout &lt;&lt; marks&#91;i] &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Important Points About Arrays<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Array size is fixed after declaration<\/li>\n\n\n\n<li>All elements must be of the same data type<\/li>\n\n\n\n<li>Indexing starts from 0<\/li>\n\n\n\n<li>Arrays store data in contiguous memory locations<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of One-Dimensional Arrays<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy data storage<\/li>\n\n\n\n<li>Fast access using index<\/li>\n\n\n\n<li>Simplifies repetitive tasks<\/li>\n\n\n\n<li>Useful for loops and calculations<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Disadvantages of Arrays<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fixed size<\/li>\n\n\n\n<li>Cannot store different data types together<\/li>\n\n\n\n<li>Insertion and deletion can be difficult<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why One-Dimensional Arrays are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Arrays are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Form the base of advanced data structures<\/li>\n\n\n\n<li>Improve data management<\/li>\n\n\n\n<li>Are widely used in programming<\/li>\n\n\n\n<li>Help in sorting and searching algorithms<\/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 a row of lockers:<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779437934507\"><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>Each locker stores one item<\/li>\n\n\n\n<li>Every locker has a number<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, an array stores multiple values, and each value has an index number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">One-dimensional arrays in C++ are essential data structures used to store multiple values efficiently. They simplify data handling, improve program organization, and are widely used in real-world programming 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++ > Arrays and Strings >One-Dimensional Arrays<\/span><\/span><\/div>","protected":false},"menu_order":25,"template":"","class_list":["post-97","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>One-Dimensional Arrays - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.\" \/>\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=\"One-Dimensional Arrays - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.\" \/>\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-22T08:18:34+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=one-dimensional-arrays\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"One-Dimensional Arrays - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-20T11:36:03+00:00\",\"dateModified\":\"2026-05-22T08:18:34+00:00\",\"description\":\"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.\",\"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++ > Arrays and Strings >One-Dimensional 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":"One-Dimensional Arrays - Learn C++Language with GiGz.PK","description":"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.","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":"One-Dimensional Arrays - Learn C++Language with GiGz.PK","og_description":"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T08:18:34+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=one-dimensional-arrays","url":"https:\/\/gigz.pk\/","name":"One-Dimensional Arrays - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-20T11:36:03+00:00","dateModified":"2026-05-22T08:18:34+00:00","description":"Learn C++ one-dimensional arrays with examples to store, access, and manage multiple values using indexes and loops.","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++ > Arrays and Strings >One-Dimensional 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\/97","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=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}