DIR Return Create A Forum - Home
---------------------------------------------------------
techsuns
HTML https://techsuns.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: OutPut of a Program
*****************************************************
#Post#: 432--------------------------------------------------
output
By: dinesh Date: January 29, 2013, 9:57 am
---------------------------------------------------------
# include <iostream>
# include <string.h>
using namespace std;
struct test
{
char str[20];
};
int main()
{
struct test st1, st2;
strcpy(st1.str, "GeeksforGeeks");
st2 = st1;
st1.str[0] = 'X';
st1.str[1] = 'Y';
/* Since copy was Deep, both arrays are different */
cout << "st1's str = " << st1.str << endl;
cout << "st2's str = " << st2.str << endl;
return 0;
}
#Post#: 434--------------------------------------------------
Re: output
By: kpr29 Date: January 29, 2013, 10:09 pm
---------------------------------------------------------
@Majeti: Output
XeeksforGeeks
GYeksforGeeks
#Post#: 437--------------------------------------------------
Re: output
By: dinesh Date: January 29, 2013, 10:25 pm
---------------------------------------------------------
What is the output for the following
# include <iostream>
# include <string.h>
using namespace std;
struct test
{
char *str;
};
int main()
{
struct test st1, st2;
st1.str = new char[20];
strcpy(st1.str, "GeeksforGeeks");
st2 = st1;
st1.str[0] = 'X';
st1.str[1] = 'Y';
/* Since copy was shallow, both strings are same */
cout << "st1's str = " << st1.str << endl;
cout << "st2's str = " << st2.str << endl;
return 0;
}
Can anyone explain further...
#Post#: 438--------------------------------------------------
Re: output
By: kpr29 Date: January 30, 2013, 12:06 am
---------------------------------------------------------
@Majeti: Nice Question............
Output:
XYeksforGeeks
XYeksforGeeks
#Post#: 439--------------------------------------------------
Re: output
By: kranthipls Date: January 30, 2013, 3:14 am
---------------------------------------------------------
good one
*****************************************************