Hi i'm studying pointers now. But while studying, I have a question and I want to ask
#include<stdio.h>
void store1(char **p){
char *tmp = "hello";
*p = tmp;
return;
}
void store2(char *p){
char *tmp = "hello";
p = tmp;
return;
}
int main(){
char *p;
//store1(&p, num);
store2(p);
printf("%s\n", p);
}
This is my questions Why does store1 function not have a segment fault and store2 function has a segment fault?
Why should we pass a variable of type char** as an argument to store a string?
If the char* type is passed as an argument, the char* tmp variable and the type match, so shouldn't it be stored in p?
Please let me know, smart brothers