So I'm a beginner with C programming and understanding pointers and how to use them is still giving me some trouble. Here I'm simply trying to iterate through an array using a pointer. I've got this bit of code below but instead of ending at 55, it prints an additional value (32765). First, could someone explain to me why I'm getting an extra value? Second, could someone tell me how to limit this program to the values in the array? I tried using *pntr < 5 for the condition but then nothing prints.
void iterate(int* li) {
for (int *pntr = li; *pntr; pntr++) {
printf("%d\n", *pntr);
}
}
int main(){
int values[] = {11, 22, 33, 44, 55};
iterate(values);
}
*pntrdoes oncepntrno longer points to any of your valuesintarray to be null-terminated, so yourforloop termination condition doesn't need to be met.