|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
C and structural problems. Thank you for your excellent suggestion. Confused.
#include "Iostream.h>
Struct structA
{
Int iMember;
Char *cMember;
Int *iTest;
};
Int main (int argc, char* argv[])
{
StructA instant1, instant2;
Char c = 'a';
Int j = 100;
Int i = parts
Instant1.iMember = 1;
Instant1.cMember = &c;
(Instant1.iTest) = &j;
Instant2 = instant1;
Cout "" "* (instant1.cMember) is" the "<* (instant1.cMember)," "endl;
Cout "" "* (instant1.iTest) is the" "" * (instant1.iTest), "" endl;
* (Instant2.cMember) = 'b';
Instant2.iTest = &i;
Cout<< "" "" endl;
Cout "" "* (instant1.cMember) is the" "" * (instant1.cMember), "" endl;
Cout "" "* (instant1.iTest) is the" "" * (instant1.iTest), "" endl;
Cout "" * (instant2.cMember), "" endl;
Cout "" * (instant2.iTest), "" endl;
Return 0
}
Following is the output
* (Instant1.cMember) is a
* (Instant1.iTest) is 100
* (Instant1.cMember) is b
* (Instant1.iTest) is 100
B
200
The question is :
= Instant1; in instant2, why instant2 instant1.cMember will become the value and instant1.iTest
Not?
Second, if the process is C.
Following
#include "Stdio.h>
Struct structA
{
Int iMember;
Char *cMember;
Int *iTest;
};
Int main (int argc, char* argv[])
{
Struct structA instant1, instant2;
Char c = 'a';
Int j = 100;
Int i = parts
Instant1.iMember = 1;
Instant1.cMember = "LIANG" ;//&c;
(Instant1.iTest) = &j;
Instant2 = instant1;
Printf ( "instant1.cmember=[%s]\n" (instant1.cMember));
Printf ( "instant1.iTest=[%d]\n" * (instant1.iTest));
(Instant2.cMember) = "Zeng" ;// 'b';
Instant2.iTest = &i;
Printf ( "instant2.cmember=[%s]\n" (instant2.cMember));
Printf ( "instant2.iTest=[%d]\n" * (instant2.iTest));
Printf ( "instant1.cmember=[%s]\n" (instant1.cMember));
Printf ( "instant1.iTest=[%d]\n" * (instant1.iTest));
Return 0
}
Output
Instant1.cmember=[LIANG]
Instant1.iTest=[100]
Instant2.cmember=[Zeng]
Instant2.iTest=[200]
Instant1.cmember=[LIANG]
Instant1.iTest=[100]
With instant2 instant1.cmember and instant1.iTest why not change? |
The first issue, I suggest you re-learn and use guidelines
C and C + + address the problem early on is the understanding of men, and we must learn
Secondly, I do not help you |
[B] [/b] a C + + examples :
Your question is :
= Instant1; in instant2, why instant2 instant1.cMember will become the value and instant1.iTest not?
[code]
//instant1.cMember With instant2.cMember is at the same place.
4003rd you change the content at the destination, of course, all the people could see the change at the spot
* (Instant2.cMember) = 'b';
//instant2.iTest Are also targets, but you have not changed the content at the destination.
4003rd instead at the change, pointing to another person, of course, only instant2 can change, how can others how
Instant2.iTest = &i;
[/code]
[B] [/b] second c examples :
Your question is :
With instant2 instant1.cmember and instant1.iTest why not change?
[code]
4003rd on the issue with similar changes are two of his fingers, and no change in others
(Instant2.cMember) = "Zeng" ;// 'b';
Instant2.iTest = &i;
[/code] |
Thank you Sentence awoke dreamer. |
I started to have been blindfolded.
Instant2.iTest = &i;
Cout<< "" "" endl;
Cout "" "* (instant1.cMember) is the" "" * (instant1.cMember), "" endl;
Cout "" "* (instant1.iTest) is the" "" * (instant1.iTest), "" endl;
Instan2 which is changing at the unit, no change instan1.iTest value, the problem with the procedure will prove short point |
| |