Let's say I have a dynamically allocated array of structs of which I do not know the size, we'll call it *people. Now, I'm asked to check if this array has at least 12 elements, or structs, within it. Because it is dynamically allocated, I know sizeof() will not work, but what happens if I do something like the following?
int count = 0;
for (int i = 0; i <= 12; i++) {
if (people[i] == NULL) { <----- will this work?
exit(1);
}
count++;
}
printf("array has 12 or more elements");
Basically, my question is, would people[i] return NULL if the index, i, is greater than the size of the dynamically allocated array? If not, how would one go about checking if the array size is greater than a certain number (in this case 12)?