I made a histogram and try to find the length of a histogram. But the length of the histogram give me the wrong output. Here is my code first.
int *n = calloc(l,sizeof(int));
for (int i = 0; i < l; i++) {
scanf("%d", &n[i]);
}
int *hist = (int*) malloc(sizeof(int));
for (int i = 0; i<l; i++){
hist[n[i]]++;
hist = realloc(hist, sizeof(int));
}
//length of histogram array
int histlen = sizeof(hist)/sizeof(hist[0]);
printf("legnth : %d\n", histlen);
So
input: 3 3 3 2 2 1
the output should be
length:3
But my code give me
length:2
What is the problem?