S
suman.nandan
Hi Experts,
In the following code (sorry for using C printf in the code !) :
----------------------------------------------
#include <string>
#include<cstdio>
using namespace std;
int main ()
{
string a1 = "abcd";
string a2;
a2 = a1;
printf("Address of a1.c_str() is = %u\n", a1.c_str());
printf("Address of a2.c_str() is = %u\n", a2.c_str());
}
---------------------------------------------
The output I am getting is :
Address of a1.c_str() is = 159920148
Address of a2.c_str() is = 159920148
----------------------------------------------
I seems that the copy happening here is a shallow one.
I have also tried with copy constructor.
This seems to be counter intuitive. Is this expected ?
Thanks,
Suman.
In the following code (sorry for using C printf in the code !) :
----------------------------------------------
#include <string>
#include<cstdio>
using namespace std;
int main ()
{
string a1 = "abcd";
string a2;
a2 = a1;
printf("Address of a1.c_str() is = %u\n", a1.c_str());
printf("Address of a2.c_str() is = %u\n", a2.c_str());
}
---------------------------------------------
The output I am getting is :
Address of a1.c_str() is = 159920148
Address of a2.c_str() is = 159920148
----------------------------------------------
I seems that the copy happening here is a shallow one.
I have also tried with copy constructor.
This seems to be counter intuitive. Is this expected ?
Thanks,
Suman.