{"id":5177,"date":"2014-03-30T19:26:32","date_gmt":"2014-03-30T19:26:32","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/size-of-a-pointer-allocated-by-malloc-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:26:32","modified_gmt":"2014-03-30T19:26:32","slug":"size-of-a-pointer-allocated-by-malloc-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/size-of-a-pointer-allocated-by-malloc-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"size of a pointer allocated by malloc [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>you must be using 64 bit system\/OS, thats why it printed 8 for printf(&#8220;%d&#8221;, sizeof(pointer));<\/p>\n<p>when you declare char *p; it will reserve space equalto sizeof(char *) in you memory.<\/p>\n<p>now if the system is 64-bit it will reserve 8 bytes or if it is 32-bit then it will reserve 4 bytes.<\/p>\n<p>now<\/p>\n<pre><code>char* pointer;\npointer = malloc (20000);\n<\/code><\/pre>\n<p>when you define pointer = malloc(20000) it will reserve a block of 20000 bytes in memory where pointer points to the first byte of that block it doesnt allocates 20000 bytes to pointer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>you must be using 64 bit system\/OS, thats why it printed 8 for printf(&#8220;%d&#8221;, sizeof(pointer)); when you declare char *p; it will reserve space equalto sizeof(char *) in you memory. now if the system is 64-bit it will reserve 8 bytes or if it is 32-bit then it will reserve 4 bytes. now char* pointer; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5177","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5177"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5177\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}