{"id":13668,"date":"2022-12-10T15:08:09","date_gmt":"2022-12-10T15:08:09","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=13668"},"modified":"2022-12-10T15:44:41","modified_gmt":"2022-12-10T15:44:41","slug":"const-correctness-c-vs-c-differences","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=13668","title":{"rendered":"Const Correctness \/ C vs. C++ Differences"},"content":{"rendered":"<p><a href=\"http:\/\/www.parashift.com\/c++-faq-lite\/const-correctness.html\">Const correctness<\/a><br \/>\n<a href=\"https:\/\/isocpp.org\/wiki\/faq\/const-correctness\">Const Correctness<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/9834067\/difference-between-char-and-const-char\">Difference between char* and const char*?<\/a><\/p>\n<p><code>char*<\/code> is a <strong>mutable<\/strong> pointer to a <strong>mutable<\/strong> character\/string.<\/p>\n<p><code>const char*<\/code> \/ <code>char const *<\/code> is a <strong>mutable<\/strong> pointer to an <strong>immutable<\/strong> character\/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from <code>const char *<\/code> to <code>char*<\/code> is deprecated.<\/p>\n<p><code>char * const<\/code> is an <strong>immutable<\/strong> pointer (it cannot point to any other location) <strong>but<\/strong> the contents of location at which it points are <strong>mutable<\/strong>.<\/p>\n<p><code>const char* const<\/code> \/ <code>char const * const<\/code> is an <strong>immutable<\/strong> pointer to an <strong>immutable<\/strong> character\/string.<\/p>\n<p><a href=\"https:\/\/www.tarleton.edu\/faculty\/agapie\/documents\/cosc2321\/cosc_2321_ch04_data-abstraction.pdf\">Quiz<\/a> (PDF)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Const correctness Const Correctness Difference between char* and const char*? char* is a mutable pointer to a mutable character\/string. const char* \/ char const * is a mutable pointer to an immutable character\/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13668","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13668"}],"version-history":[{"count":4,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13668\/revisions"}],"predecessor-version":[{"id":13672,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/13668\/revisions\/13672"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}