Hi, I have just one question :
how to know the size of an array, i have un little program, i use
first static, ant i can use sizeof() to know the size,
but when i put it as paremeter in the function, size of return "1".
ex
int tab[10];
printf("%d",siz eof(tab)/sizeof(int)); // print 10
int length(int *tab)
{
return sizeof(tab)/sizeof(int); // return 1
}
dynamic case :
int *tab = malloc(sizeof(i nt)*10);
printf("%d",siz eof(tab)/sizeof(int)); // print 1
Why the result aren't the same ?
How can i know the size of the array, without save the size ?
Thanks a lot.
how to know the size of an array, i have un little program, i use
first static, ant i can use sizeof() to know the size,
but when i put it as paremeter in the function, size of return "1".
ex
int tab[10];
printf("%d",siz eof(tab)/sizeof(int)); // print 10
int length(int *tab)
{
return sizeof(tab)/sizeof(int); // return 1
}
dynamic case :
int *tab = malloc(sizeof(i nt)*10);
printf("%d",siz eof(tab)/sizeof(int)); // print 1
Why the result aren't the same ?
How can i know the size of the array, without save the size ?
Thanks a lot.
Comment