Hi All,
Alternative function declaration: //Function 2Code:#include <stdio.h> #include <string.h> #include <stdlib.h> //First funtion void func(char *p) { p = "Hello"; // Statement 1 } int main() { char *p = NULL; func(&p,&c); printf("Val of p:%s\n",p); }
Code:void func(char **p) { *p = "Hello"; // Statement 2 }
What is confusing to me is the outputs:
With the function declared as in Function 1:
<NULL>
With the function declared as in Function 2:
Hello
Doubts:
1. How come Statement 1 is valid?
2. Will address be assigned to the pointer variable p in Statement 1?
3. What is the difference b/w *p="Hello" and p="Hello"?
4. how is that by calling Function 2 instead of Function 1 it prints Hello?
Thanks in advance