I need to know how many elements are allocated in my pointer pointer. For example with vector, sizeof(v)/sizeof(v[0])
in this way I get the number of elements that vector has. I would like to do the same, but with pointers.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[]){
int *p = malloc(5*sizeof(int)), n;
n = sizeof(p)/sizeof(int);
printf("%d\n", n);
return 0;
}
In this code I already know how much elements have, just print the variable n
, however I will use this in a function where I do not know the value of n
.