{"id":122,"date":"2009-07-24T11:43:02","date_gmt":"2009-07-24T10:43:02","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=122"},"modified":"2009-07-24T11:43:25","modified_gmt":"2009-07-24T10:43:25","slug":"pointers","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/pointers\/","title":{"rendered":"Pointers"},"content":{"rendered":"<p>Pointers are pointers to memory, the variable that is defined as a pointer still holds the same area in memory as the type of the pointer e.g. char and int are of different size in memory, just do a <\/p>\n<pre lang=\"cpp\">cout << sizeof(char) << sizeof(int);<\/pre>\n<p> to find out.<\/p>\n<p>The actually pointer holds the address of the variable it is pointing to, e.g.<\/p>\n<p>The value variable<\/p>\n<p>Value = 10, address within the memory for value = 4<\/p>\n<p>The pointer<\/p>\n<p>ValuePointer = 4 (the address of the value), address within the memory = 200<\/p>\n<p>The valuepointer actually equals 4, the memory of the value variable, if you use the * (pointer) then you will get the value pointed to, 10, and if you use the & (address) you will get 200 which is the place in memory where the valuepointer is placed in memory.<\/p>\n<p>For example<\/p>\n<pre lang=\"cpp\">\r\nint main()\r\n{\r\nint value1 = 10;\r\nint *valp = &value1;       \/\/ equals the memory address of value1\r\n\r\nstd::cout << \"Value 1 = \" << value1 << \" address = \" << &#038;value1 << \"\\n\";\r\nstd::cout << \"Value p = \" << *valp << \" address = \" << &#038;valp << \" pointed to memory \" << valp << \"\\n\";\r\nstd::cout << \"The value p pointerd to memory is the same as the memory address as value 1\\n\";\r\nstd::cout << \"The value p = the pointerd memory value that is assoicated with the value that is in valp (address of memory)\\n\";\r\n\r\n(*valp)++;              \/\/ correct increament the value that is pointed to by the address held by vapl\r\nstd::cout << \"Value 1 = \" << value1 << \" address = \" << &#038;value1 << \"\\n\";\r\nstd::cout << \"Value p = \" << *valp << \" address = \" << &#038;valp << \" pointed to memory \" << valp << \"\\n\";\r\n\r\n*valp++;              \/\/ incorrect will increament the address that is held valp by sizeof(int) (usually 4)\r\nstd::cout << \"Value 1 = \" << value1 << \" address = \" << &#038;value1 << \"\\n\";\r\nstd::cout << \"Value p = \" << *valp << \" address = \" << &#038;valp << \" pointed to memory \" << valp << \"\\n\";\r\n\r\nreturn 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pointers are pointers to memory, the variable that is defined as a pointer still holds the same area in memory as the type of the pointer e.g. char and int are of different size in memory, just do a cout<\/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-122","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\/122","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=122"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}