N
Newbie
Hi,
I'm a newbie. I need to clear my pointer concepts.
the code below gives segmentation fault when i use char* str;
int main()
{
char *str;
printf("Enter a string to reverse\n");
scanf("%s",&str);
strlen(str);
}
if I use char str[20] it runs fine.
int main()
{
char str[20];
printf("Enter a string to reverse\n");
scanf("%s",&str);
strlen(str);
}
Can you please explain why?
Thanks
I'm a newbie. I need to clear my pointer concepts.
the code below gives segmentation fault when i use char* str;
int main()
{
char *str;
printf("Enter a string to reverse\n");
scanf("%s",&str);
strlen(str);
}
if I use char str[20] it runs fine.
int main()
{
char str[20];
printf("Enter a string to reverse\n");
scanf("%s",&str);
strlen(str);
}
Can you please explain why?
Thanks