#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int foo(char str[])
{
char *str1=(char *)malloc(sizeof(char )*sizeof(str));
printf("\n str %s size : %zu \n",str,sizeof(str));
}
int main()
{
char str[]="879879879-=-=-@#$@#$abcd";
printf("\n str %s size : %zu \n",str,sizeof(str));
foo(str);
return 0;
}
Why is string length different in main()
and foo()
?
This is a simple program in which main
calls foo
with str
— the same str
which is showing length 25 in main
and in foo
8: why?
Output:
str 879879879-=-=-@#$@#$abcd size : 25
str 879879879-=-=-@#$@#$abcd size : 8