GeeksforGeeks » C/C++ Programming Questions
Sizeof dynamic array
(2 posts)-
How can you find the sizeof a dynamically created array?
Eg: int *arr = (int *)malloc(sizeof(int)*int);
sizeof(arr) will give you 4 as arr pointer. Is there anything like finding the sizeof of int without using sizeof operator.
-
I don't think there is any standard way of doing so. If you need size later in code then you can store the size in one variable and use it.
int size = sizeof(int)*int;
int *arr = (int *)malloc(size);
Reply
You must log in to post.