I just wanna know why such a wierd output is seen for the following program.I know it is pretty simple but i can't make it.Just a clue could help me to sort out the issue.
Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <stdio.h>
- void func(char *s)
- {
- printf("%x \n",s);
- s="senthil";
- printf("%s %x\n",s,s);
- }
- int main()
- {
- char* s ="manikandan";
- printf("%s %x\n",s,s);
- func(s);
- cout<<s;
- }
./a.out
manikandan 4eb0
4eb0 >>>>>>>>>> Same address is passed to func()
senthil 4ea0 >>>>>Here the address is diff !!!
manikandan
Can't we change the value of a string using char pointer.