I'm experimenting with C void functions and strings. I've tried this program:
#include <stdio.h>
#include <string.h>
void print(char** test);
int main(){
char* test = "abcdef";
print(&test);
return 0;
}
void print(char** test){
for(int i=0;i<strlen(*test);i++)
printf("%c\n",*test[i]);
}
It prints for me the first a A �
then segmentation fault. But after changing *test[i]
to *(*test+i)
which is pretty much the same thing it works for me as expected.
Is there any subtle difference *test[i]
and *(*test+i)
if not, why my code works in second examples meanwhile it doesn't in the first ?