{"id":533,"date":"2016-01-19T00:15:07","date_gmt":"2016-01-18T23:15:07","guid":{"rendered":"http:\/\/andras.palfi.hu\/?p=533"},"modified":"2016-01-19T00:15:07","modified_gmt":"2016-01-18T23:15:07","slug":"const-pointer-to-const-memory-what","status":"publish","type":"post","link":"https:\/\/andras.palfi.hu\/?p=533","title":{"rendered":"const pointer to const memory&#8230; what?"},"content":{"rendered":"<p>\t\t\t\tAfter several years I found lots of people &#8211; and me \ud83d\ude42 &#8211; still confused about the pointer declarations &#8211; if it contains some const keyword somewhere.<\/p>\n<p>So\u00a0<em>const char *\u00a0<\/em>or\u00a0<em>char const *<\/em> or\u00a0<em>char * const<\/em> still confusing.<\/p>\n<p>To keep it simple: <strong>read it backward<\/strong> as this excellent post describes:\u00a0<a href=\"http:\/\/c-faq.com\/decl\/spiral.anderson.html\" target=\"_blank\" rel=\"noopener noreferrer\">Clockwise\/Spiral rule<\/a><\/p>\n<p>So:<\/p>\n<ul>\n<li><em>const char *\u00a0<\/em>is equivalent to\u00a0<em>char const *<\/em> : <strong>pointer<\/strong> <strong>to a<\/strong> <strong>const<\/strong>ant<strong> char<\/strong>acter (character constant).\u00a0It means you can change the pointer &#8211; so it points to somewhere else &#8211; but cannot change the memory at that address.<\/li>\n<li><em>char * const<\/em> : <strong>const<\/strong>ant <strong>pointer<\/strong> <strong>to a<\/strong> <strong>char<\/strong>acter. It means you cannot change the pointer value &#8211; but you can change the memory at that address<\/li>\n<li><em>const char * const<\/em> which is equal to\u00a0<em>char const * const<\/em> is the one where you cannot change anything &#8211; constant pointer to a constant character.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After several years I found lots of people &#8211; and me \ud83d\ude42 &#8211; still confused about the pointer declarations &#8211; if it contains some const keyword somewhere. So\u00a0const char *\u00a0or\u00a0char const * or\u00a0char * const still confusing. To keep it simple: read it backward as this excellent post describes:\u00a0Clockwise\/Spiral rule So: const char *\u00a0is equivalent [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":"","footnotes":""},"categories":[17,3],"tags":[],"_links":{"self":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts\/533"}],"collection":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=533"}],"version-history":[{"count":0,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts\/533\/revisions"}],"wp:attachment":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}