# Thread: I have trouble understanding this code

1. ## I have trouble understanding this code

This might be a stupid question, but I thought arrays start from index 0. So when we say print_array(data, 3)why is it only printing 10 20 30? why 40 is not included? isnt 40 index 3?!
I will appreciate if anyone can clarify this for me.

Code:
```#include <stdio.h>
void print_array(int *p, int size) {  /* int *p could have been written as int p[] */   int idx = 0;
for (idx = 0; idx < size; idx++) {      printf("%d\n", p[idx]);   }
printf("In print_array function size of array using sizeof: %ld\n", sizeof(p));}
int main() {   int data[] = {10, 20, 30, 40, 50, 60};
print_array(data, 3);   /* data = NULL;  What happens if we try this assignment? */
printf("Size of data array using sizeof: %ld\n", sizeof(data));
return 0;}```

Code:
```out put is:
10
20
30
In print_array function size of array using sizeof: 4
Size of data array using sizeof: 24```

2. for (idx = 0; idx < size

so that is while idx < 3 = 0,1,2

and that look right as you are asking for 3 units,
print_array(data, 4); // ask for 4 units 0-3

3. Think of it saying print 3 elements versus what index to print.