c - Different array sizes -
this question has answer here:
when run following program, different array sizes. tired different ways result same, io doing wrong ?
#include<stdio.h> void array_size(char *a[]) { printf("func array size: %d\n", sizeof(a)); } int main() { char *str_array[]={"one", "two", "three"}; printf("array size: %d\n", (int)sizeof(str_array)); array_size(str_array); return 0; }
in function main str_array
array 3 char *
.
the parameter a
of function array_size pointer. compiler not dynamically pass array length information when calling array_size.
the size of 1 pointer not equal size of 3 char *
pointers.