I have a program below
void swap(char **s1,char **s2);
int main()
{
char *list[] = {
"Das",
"Kannan",
"Rajendran",
"Shahul"
};
printf("Before swap list[0] = %s,list[1] = %s\n",*list[0],*list[1]);
swap(&list[0],&list[1]);
printf("After swap list[0] = %s,list[1] = %s\n",*list[0],*list[1]);
return 0;
}
void swap(char **s1,char **s2)
{
char *t;
t = *s1;
*s1 = *s2;
*s2 = t;
}
I am trying to swap the addresses of list[0] and list[1].
Visual Studio 2008 is generating an error while running(Start debugging) this program. The error generated was
Unhandled exception at 0x1029984f (msvcr90d.dll) in ConsoleApp.exe: 0xC0000005: Access violation reading location 0x00000044.
No compilation errors.
May I know why pointer to pointer used doesn't work properly.
Also want to know why
void swap(char *s1,char *s2)
also didn't work.