Pointer array length

If I have an array of pointers of type char ** strings, how can I determine its length? Thanks

+3
source share
5 answers

You can not. You must manually track the length of the arrays.

+7
source

You cannot reliably.

Sometimes there is a null pointer denoting the end - this is one of the conventions used earlier. Most often you need to tell the length.

But there is no reliable way to determine the length. You must somehow know (or say) the length.

+4
source

, .

+1

. , NULL.

char** lines = mysteryfunction();
for ( ;*lines;lines++ ) { 
    printf( "%s\n", *list ); 
}
+1

char *array[]={"welcome","to","India"};

length=sizeof(array)/sizeof(array[0]);

:

3

, ( )

Because there is no predefined function to get the length of the array.

-1
source

Source: https://habr.com/ru/post/1707719/


All Articles