{"id":3175,"date":"2021-06-11T11:05:00","date_gmt":"2021-06-11T05:35:00","guid":{"rendered":"https:\/\/manorinfinity.com\/blog\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/"},"modified":"2021-06-11T11:05:00","modified_gmt":"2021-06-11T05:35:00","slug":"dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs","status":"publish","type":"post","link":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/","title":{"rendered":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |"},"content":{"rendered":"<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: left;\"><span style=\"font-family: courier; font-size: large; font-weight: 700; white-space: pre-wrap;\">Dynamic Memory Allocation:<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">When we need to change the size of data structure at runtime, then we use dynamic memory allocation. C language provides some functions for dynamic memory allocation. There are 4 library functions in C language that are defined under the &#8216;stdlib.h&#8217; header file to facilitate dynamic memory allocation.<\/span><\/span><\/p>\n<ol style=\"margin-bottom: 0px; margin-top: 0px; padding-inline-start: 48px;\">\n<li aria-level=\"1\" dir=\"ltr\" style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;\">\n<p dir=\"ltr\" role=\"presentation\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 12pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">malloc()<\/span><\/span><\/p>\n<\/li>\n<li aria-level=\"1\" dir=\"ltr\" style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;\">\n<p dir=\"ltr\" role=\"presentation\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">calloc()<\/span><\/span><\/p>\n<\/li>\n<li aria-level=\"1\" dir=\"ltr\" style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;\">\n<p dir=\"ltr\" role=\"presentation\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">free()<\/span><\/span><\/p>\n<\/li>\n<li aria-level=\"1\" dir=\"ltr\" style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;\">\n<p dir=\"ltr\" role=\"presentation\" style=\"line-height: 1.38; margin-bottom: 12pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">realloc()<\/span><\/span><\/p>\n<\/li>\n<\/ol>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">In order to use dynamic memory allocation, a <\/span><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\">heap segment<\/span><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"> is used.<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. malloc() :<\/span><\/span><\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">We use &#8216;malloc&#8217; or &#8216;memory allocation&#8217; to dynamically allocate a single large block of memory with the given size. This function returns a pointer of &#8216;void&#8217; type, later on we can cast this pointer into a pointer of any type.&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Syntax: pointer = (cast_type *)malloc(byte_size);<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Example:&nbsp;<\/span><\/span><\/p>\n<p><span style=\"font-family: courier; font-size: large;\"><\/span><\/p>\n<p style=\"text-align: left;\"><span><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/span><\/p>\n<div style=\"text-align: center;\">\n<div style=\"clear: both; text-align: center;\"><span style=\"font-family: courier; font-size: large;\"><img data-recalc-dims=\"1\" decoding=\"async\" border=\"0\" data-original-height=\"301\" data-original-width=\"281\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/assd.png?ssl=1\" \/><\/span><\/div>\n<\/div>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">In the allocated memory, &#8216;ptr&#8217; pointer have the address of the first byte. If allocation fails, hence the space is insufficient, then this function returns a NULL pointer.&nbsp;<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">2. calloc() :<\/span><\/span><\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">We can use the &#8216;calloc&#8217; or &#8216;continuous allocation&#8217; function to dynamically allocate the specified number of blocks of memory of the specified type. This function initializes each block with the default value &#8216;0&#8217;.&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Syntax: pointer = (cast_type *)malloc(n, element_size);<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Example:&nbsp;<\/span><\/span><\/p>\n<p><span style=\"font-family: courier; font-size: large;\"><\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: courier; font-size: large; white-space: pre-wrap;\">&nbsp;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: center;\"><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><\/span><\/p>\n<div style=\"clear: both; text-align: center;\"><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><img data-recalc-dims=\"1\" decoding=\"async\" border=\"0\" data-original-height=\"301\" data-original-width=\"281\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/assd-2B-25281-2529.png?ssl=1\" \/><\/span><\/div>\n<p><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><br \/><span><br \/><\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">If the space is insufficient, then allocation will fail and this function returns a NULL pointer.<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">3. free() :<\/span><\/span><\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">After dynamically allocation of the memory, in order to have a good programming habit, we must dynamically deallocate the memory. The memory allocated by the function malloc() and calloc() will not deallocate on their own.&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Hence, we can use free() whenever memory allocation takes place. This function helps to reduce the wastage of memory, by freeing it.<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Example:&nbsp;<\/span><\/span><\/p>\n<p><span style=\"font-family: courier; font-size: large;\"><\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">4. realloc() :<\/span><\/span><\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Let&#8217;s consider a situation, we used any function either malloc() or calloc() to dynamically allocate the memory. But now we want to change the specified size of the previously allocated memory because it becomes insufficient. Then we can use, realloc() function to dynamically re-allocate the memory.<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Syntax: pointer = realloc(pointer, new_size);<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Here &#8216;pointer&#8217; will be re-allocated with the new size. This function will return NULL, if allocation fails, hence the space is insufficient.<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Example:&nbsp;<\/span><\/span><\/p>\n<p><span style=\"font-family: courier; font-size: large;\"><\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><\/span><\/p>\n<div style=\"clear: both; text-align: center;\"><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><img data-recalc-dims=\"1\" decoding=\"async\" border=\"0\" data-original-height=\"301\" data-original-width=\"281\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/assd-2B-25282-2529.png?ssl=1\" \/><\/span><\/div>\n<div style=\"clear: both; text-align: center;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/div>\n<p><span style=\"background-color: transparent; color: black; font-family: courier; font-size: large; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><\/p>\n<div style=\"clear: both; text-align: center;\"><img data-recalc-dims=\"1\" height=\"164\" width=\"300\" decoding=\"async\" border=\"0\" data-original-height=\"301\" data-original-width=\"551\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/assd-2B-25285-2529-300x164.png?resize=300%2C164&#038;ssl=1\" \/><\/div>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">The size of the &#8216;ptr&#8217; is dynamically changed from 20 bytes to 40 bytes.&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\"><\/span><\/span><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">If you find any problem related to this article, please comment below or contact me <\/span><span style=\"font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;\"><a href=\"https:\/\/www.bitsofcs.xyz\/p\/contact-me.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/span><span style=\"font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dynamic Memory Allocation: When we need to change the size of data structure at runtime, then we use dynamic memory allocation. C language provides some functions for dynamic memory allocation. There are 4 library functions in C language that are defined under the &#8216;stdlib.h&#8217; header file to facilitate dynamic memory&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\">Read the post<span class=\"screen-reader-text\">Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":3212,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-infinity-fitness","excerpt","zoom","full-without-featured","even","excerpt-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.12 (Yoast SEO v26.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS | ManOrInfinity<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |\" \/>\n<meta property=\"og:description\" content=\"Dynamic Memory Allocation: When we need to change the size of data structure at runtime, then we use dynamic memory allocation. C language provides some functions for dynamic memory allocation. There are 4 library functions in C language that are defined under the &#8216;stdlib.h&#8217; header file to facilitate dynamic memory&#8230;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\" \/>\n<meta property=\"og:site_name\" content=\"ManOrInfinity\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-11T05:35:00+00:00\" \/>\n<meta name=\"author\" content=\"manorinfinity\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:site\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"manorinfinity\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\"},\"author\":{\"name\":\"manorinfinity\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"headline\":\"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |\",\"datePublished\":\"2021-06-11T05:35:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\"},\"wordCount\":385,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"Infinity Fitness\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\",\"url\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\",\"name\":\"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS | ManOrInfinity\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2021-06-11T05:35:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/manorinfinity.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\",\"url\":\"https:\/\/manorinfinity.com\/blog\/\",\"name\":\"ManOrInfinity\",\"description\":\"Thrive towards greatness\",\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\",\"name\":\"manorinfinity\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"contentUrl\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"width\":282,\"height\":260,\"caption\":\"manorinfinity\"},\"logo\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being\",\"sameAs\":[\"http:\/\/manorinfinity.com\"],\"url\":\"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS | ManOrInfinity","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/","og_locale":"en_US","og_type":"article","og_title":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |","og_description":"Dynamic Memory Allocation: When we need to change the size of data structure at runtime, then we use dynamic memory allocation. C language provides some functions for dynamic memory allocation. There are 4 library functions in C language that are defined under the &#8216;stdlib.h&#8217; header file to facilitate dynamic memory&#8230;","og_url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/","og_site_name":"ManOrInfinity","article_published_time":"2021-06-11T05:35:00+00:00","author":"manorinfinity","twitter_card":"summary_large_image","twitter_creator":"@manorinfinity","twitter_site":"@manorinfinity","twitter_misc":{"Written by":"manorinfinity","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#article","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/"},"author":{"name":"manorinfinity","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"headline":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |","datePublished":"2021-06-11T05:35:00+00:00","mainEntityOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/"},"wordCount":385,"commentCount":0,"publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage"},"thumbnailUrl":"","articleSection":["Infinity Fitness"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/","url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/","name":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS | ManOrInfinity","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage"},"thumbnailUrl":"","datePublished":"2021-06-11T05:35:00+00:00","breadcrumb":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/11\/dynamic-memory-allocation-malloc-calloc-free-realloc-bitsofcs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/manorinfinity.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Dynamic Memory Allocation | malloc() | calloc() | free() | realloc() | BitsOfCS |"}]},{"@type":"WebSite","@id":"https:\/\/manorinfinity.com\/blog\/#website","url":"https:\/\/manorinfinity.com\/blog\/","name":"ManOrInfinity","description":"Thrive towards greatness","publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901","name":"manorinfinity","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","contentUrl":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","width":282,"height":260,"caption":"manorinfinity"},"logo":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/"},"description":"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being","sameAs":["http:\/\/manorinfinity.com"],"url":"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/comments?post=3175"}],"version-history":[{"count":0,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3175\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/media?parent=3175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/categories?post=3175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/tags?post=3175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}