How to Find Size of Dynamic Array in C? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In C, dynamic memory allocation allows us to manage memory resources during the execution of a program. It’s particularly useful when dealing with arrays where the size isn’t known at compile time. In this article, we will learn how to find the size of a dynamically allocated array in C. Find Size of a Dynamically Allocated Array in CWhen we dynamically allocate an array using the malloc, calloc, or realloc functions, the size of the array isn’t stored anywhere in memory. Therefore, there’s no direct way to find the size of a dynamically allocated array. To manage the size of a dynamically allocated array, we must keep track of the size separately. C Program to Keep the Track of Dynamically Allocated ArrayThe below program demonstrates how we can keep track of the size of a dynamically allocated array in C. C // C program to illustrate how to keep track of dynamically // allocated array #include <stdio.h> #include <stdlib.h> int main() { int size = 5; // size of the array int* arr = (int*)malloc( size * sizeof(int)); // dynamically allocated array // fill the array for (int i = 0; i < size; i++) { arr[i] = i; } // print the array for (int i = 0; i < size; i++) { printf("%d ", arr[i]); } free(arr); // free the array to avoid memory leak return 0; } Output0 1 2 3 4 Note: In C, it’s generally recommended to use structures or linked lists when you need to keep track of the size of a dynamically allocated array during runtime. This provides more flexibility and control over the memory. Create Quiz Comment K khatoono54g Follow 0 Improve K khatoono54g Follow 0 Improve Article Tags : C Programs C Language C-Arrays C-Dynamic Memory Allocation Dynamic Memory Allocation C Examples +2 More Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like