Click here to Skip to main content
15,913,361 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: A funny thing happened to me. Who can explain? Pin
V.13-May-04 2:43
professionalV.13-May-04 2:43 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 2:52
toxcct13-May-04 2:52 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Antony M Kancidrowski13-May-04 2:53
Antony M Kancidrowski13-May-04 2:53 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Cedric Moonen13-May-04 2:54
Cedric Moonen13-May-04 2:54 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Antony M Kancidrowski13-May-04 2:50
Antony M Kancidrowski13-May-04 2:50 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 2:55
toxcct13-May-04 2:55 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Antony M Kancidrowski13-May-04 3:22
Antony M Kancidrowski13-May-04 3:22 
AnswerRe: A funny thing happened to me. Who can explain? Pin
nguyenvhn13-May-04 2:58
nguyenvhn13-May-04 2:58 
To all:

const int a=10;//Declare an int constant and init 10
int* p=(int*)&a; //Declare an int pointer p and point to address of a.
*p=100;//Change where p pointed to 100
int i=a;//Declare an int variable i and init i to value of a.
cout << "p=" << p << endl;//Print p value (address)
cout << "&a=" << &a << endl;//Print address of a
cout << "*p=" << *p << endl;//Print value at where p pointed to
cout << "a=" << a << endl;//Print value of a
cout << "i=" << i << endl;//Print value of i

And the result:

p=0012FF7C //Point to the same address of a
&a=0012FF7C //Point to the same address of p
*p=100 //But one value is 100
a=10 //And here the other value is 10
i=10 //And here the value is 10 too.

p and a have the same memory address. But it's value is difference. Why that?

PS: if I write: int* p=&a, compiler will compain as an error. So I have used a trick by casting int* p=(int*)&a. In this case, compiler ignore.
AnswerRe: A funny thing happened to me. Who can explain? Pin
Christopher Lloyd13-May-04 3:02
Christopher Lloyd13-May-04 3:02 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Cedric Moonen13-May-04 3:09
Cedric Moonen13-May-04 3:09 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Antony M Kancidrowski13-May-04 3:53
Antony M Kancidrowski13-May-04 3:53 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Nitron14-May-04 8:37
Nitron14-May-04 8:37 
AnswerRe: A funny thing happened to me. Who can explain? Pin
Antony M Kancidrowski13-May-04 3:19
Antony M Kancidrowski13-May-04 3:19 
AnswerRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 5:17
David Crow13-May-04 5:17 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 5:36
toxcct13-May-04 5:36 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 5:41
David Crow13-May-04 5:41 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 5:44
toxcct13-May-04 5:44 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 6:28
David Crow13-May-04 6:28 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 6:35
toxcct13-May-04 6:35 
GeneralRe: A funny thing happened to me. Who can explain? Pin
David Crow13-May-04 6:48
David Crow13-May-04 6:48 
AnswerRe: A funny thing happened to me. Who can explain? Pin
vividtang14-May-04 0:29
vividtang14-May-04 0:29 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Anand Paranjpe14-May-04 0:37
Anand Paranjpe14-May-04 0:37 
AnswerRe: A funny thing happened to me. Who can explain? Pin
Anand Paranjpe14-May-04 0:34
Anand Paranjpe14-May-04 0:34 
GeneralSharing violation error when loading a DLL Pin
DaFrawg13-May-04 1:08
DaFrawg13-May-04 1:08 
GeneralRe: Sharing violation error when loading a DLL Pin
bikram singh13-May-04 5:28
bikram singh13-May-04 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.