{"id":131,"date":"2009-07-24T11:58:45","date_gmt":"2009-07-24T10:58:45","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=131"},"modified":"2009-07-24T11:58:45","modified_gmt":"2009-07-24T10:58:45","slug":"array","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/array\/","title":{"rendered":"Array"},"content":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables.<\/p>\n<p>e.g. <\/p>\n<pre lang=\"cpp\">\r\nint value1 = 1;\r\nint value2 = 2;\r\nint value3 = 3;\r\nint value4 = 4;\r\nint value5 = 5;\r\nint value6 = 6;\r\n<\/pre>\n<p>and instead you could just have<\/p>\n<pre lang=\"cpp\">\r\nint values[6] = {1,2,3,4,5,6};\r\n<\/pre>\n<p>this is a example of how to manipulate the array structure.<\/p>\n<pre lang=\"cpp\">\r\n#include <iostream>\r\n\r\nint main()\r\n{\r\n       \/\/ array structure\r\n       int values[5];       \/\/ set asside 5 blocks of int(eger) size of continuous memory blocks\r\n                     \/\/ the actual points into the array are 0-4 (e.g. 5 points but start at 0)\r\n       \r\n       int values2[6] = {0,1,2,3,4,5}; \/\/ exmaple of settings the values on define time.\r\n       \r\n       \/\/ direct assigning the values.\r\n       values[0] = 5;\r\n       values[1] = 4;\r\n       values[2] = 3;\r\n       values[3] = 2;\r\n       values[4] = 1;\r\n       \r\n       \/\/could use a position pointer\r\n       for (int i = 0; i < 5; i++)\r\n       {\r\n              \/\/ display the values\r\n              std::cout << \"Value \" << i << \" : \" << values[i] << \"\\n\";\r\n       }\r\n\r\n       int *int1p = &#038;values[0];\r\n       std::cout << \"Pointer value = \" << *int1p << \"\\n\";\r\n       int1p++;              \/\/ increament the pointer to the next part of the array\r\n       std::cout << \"Pointer value = \" << *int1p << \"\\n\";\r\n       return 0;\r\n}\r\n<\/pre>\n<p>save as arrays.cpp and then compile the program, the result once executed will be <\/p>\n<pre class=\"consoleoutput\">\r\nValue 0 : 5\r\nValue 1 : 4\r\nValue 2 : 3\r\nValue 3 : 2\r\nValue 4 : 1\r\nPointer value = 5\r\nPointer value = 4\r\n<\/pre>\n<p>and include three different ways to access the values within the array.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables. e.g. int value1 = 1; int value2 = 2; int value3 = 3; int value4 = 4; int value5 = &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/array\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Array<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10,9,8,398,400],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-c_and_cpp","tag-c","tag-gcc","tag-gnu","tag-linux","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/131\/revisions\/132"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}