Study this program immediately.
#include
void hello(char *s){
while( *(s+0) != '\0'){
printf("%c\n", *(s+0));
*(s+0) = 'a'; //comment and try then as well.
s++;
}
}
int main (int argc, char *argv[]){
char a[] = "my name is saurabh jain\0";
hello(a);
printf("hello %s", a);
return 0;
}
Here incrementing s in function will not make difference to "a" as both are different pointers and pointing to same array.
But if using "s" we change the value of string then that would be reflected in main.
__Saurabh
No comments:
Post a Comment