Hi, all
i am a newbie to cprogramming , could you please point the difference of following code segments of determing length of array ??
Code:
#include <stdio.h>
#include <stdlib.h>
void print_length(void * p)
{
int len = sizeof(p) / sizeof(p[0]);
printf("the length of str is %d\n",len);
return ;
}
int main()
{
char str[11] = "hello world";
int len = sizeof(str) / sizeof(str[0]);
printf("the length of str is %d\n",len);
print_length(&str);
return 0;
}
linux@localhost:/data/learning/C/variantLen.c> gcc -o length length.c
linux@localhost:/data/learning/C/variantLen.c> ./length
the length of str is 11
the length of str is 4