Click here to Skip to main content
15,902,299 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralNT drive mapping. Pin
RobJones13-May-04 4:21
RobJones13-May-04 4:21 
GeneralRe: NT drive mapping. Pin
Antony M Kancidrowski13-May-04 4:54
Antony M Kancidrowski13-May-04 4:54 
GeneralRe: NT drive mapping. Pin
Antony M Kancidrowski13-May-04 4:56
Antony M Kancidrowski13-May-04 4:56 
GeneralUSB Pin
Jeff Bogan13-May-04 3:58
Jeff Bogan13-May-04 3:58 
GeneralRe: USB Pin
Antti Keskinen13-May-04 6:13
Antti Keskinen13-May-04 6:13 
GeneralRe: USB Pin
Jeff Bogan13-May-04 7:56
Jeff Bogan13-May-04 7:56 
GeneralEdit Boc Scrolling Pin
sweep12313-May-04 3:13
sweep12313-May-04 3:13 
QuestionA funny thing happened to me. Who can explain? Pin
nguyenvhn13-May-04 1:40
nguyenvhn13-May-04 1:40 
When doing my homework, I had this code:
<br />
....<br />
int main(){<br />
	const int a=10;<br />
	int* p=(int*)&a;<br />
	*p=100;<br />
	int i=a;<br />
	cout << "p=" << p <<  endl;<br />
	cout << "&a=" << &a << endl;<br />
	cout << "*p=" << *p << endl;<br />
	cout << "a=" << a << endl;<br />
	cout << "i=" << i << endl;<br />
return 0;<br />
}<br />


Here is the output:

p=0012FF7C
&a=0012FF7C
*p=100
a=10
i=10

I guessed that a had to be 100, but it's 10.
It seem that compiler has replaced all instance of variable a to 10 at compile time, event if a has been allocated a storage. So the trick to change a constant by casting its pointer is not effect. Is that right?

Any comment is welcome.
Thanks.
AnswerRe: A funny thing happened to me. Who can explain? Pin
V.13-May-04 2:11
professionalV.13-May-04 2:11 
AnswerRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 2:22
toxcct13-May-04 2:22 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Cedric Moonen13-May-04 2:27
Cedric Moonen13-May-04 2:27 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 2:41
toxcct13-May-04 2:41 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Cedric Moonen13-May-04 2:56
Cedric Moonen13-May-04 2:56 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 3:02
toxcct13-May-04 3:02 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Anonymous13-May-04 3:02
Anonymous13-May-04 3:02 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 3:04
toxcct13-May-04 3:04 
GeneralRe: A funny thing happened to me. Who can explain? Pin
Anonymous13-May-04 3:05
Anonymous13-May-04 3:05 
GeneralRe: A funny thing happened to me. Who can explain? Pin
toxcct13-May-04 3:09
toxcct13-May-04 3:09 
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 

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.