I want to count the total element of a dynamic array. I had search it on another source, and all I got just a static array. How I can count it from a dynamic array? Here is my code :
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *arr;
int sz, input, length;
printf("input size of array:");
scanf("%d", &sz);
arr = (int *)malloc(sz * sizeof(int));
for (int i = 0; i < sz; i++)
{
scanf("%d", &input);
}
length = sizeof(arr) / sizeof(arr)[0];
printf("Number of elements present in given array: %d", length);
return 0;
}
and the output i just get 1
PS D:\Materi Kuliah\1031101 DASPRO\Semester 1\Week-14\Review W6-W7> ./a
input size of array:6
1
1
2
2
3
3
Number of elements present in given array: 1