udit99,
This is one thing that many books fail to mention for some reason.
It's to do with the way that C++ works with chars.
Take the following declaration:
C++ treats the above as a null terminated string (c-string) rather than a pointer to char.
Your code:
Code:
#include<iostream.h>
void main()
{
void ox(char*);
char* str="Hello";
ox(str);
cout<<str;
}
void ox(char* abc)
{
cout<<abc;
abc="meory";
}
In your code above, C++ assumes that you are passing a null terminated string 'by value'.
You will need to pass a 'pointer to pointer to char' as below:
Code:
#include <iostream>
using namespace std;
void ox(char **num);
void main()
{
char *num="100";
char** pnum=0;
pnum = #
cout<<num<<endl;
ox(pnum);
cout<<num<<endl;
}
void ox(char **num)
{
*num="200";
}
You are now passing a pointer to a null terminated string. It looks more complicated than it is.
Hope that helped.