|
-
November 28th, 2005, 01:29 AM
#1
reinterpret_cast
Can anyone look at it and help me figure out how a reinterpret cast works?
Here is the code :
main()
{
int * ptr;
int i = 20;
ptr = &i;
cout<<ptr<<endl;
i = reinterpret_cast<int>(ptr);
cout<<i<<endl;
int * ptr1;
int i1 = 200;
ptr1 = &i1;
cout<<ptr1<<endl;
i= reinterpret_cast<int>(ptr1);
cout<<i1<<endl;
char* a = " This is a string";
i = reinterpret_cast<int>(a);
cout<<&a[0]<<endl<<i<<endl;
char* a1 = "This is something else";
i1 = reinterpret_cast<int>(a);
cout<<&a1[0]<<endl<<i1<<endl;
}
and here is the o/p:
0012FF78
1245048
0012FF70
200
This is a string
4636728
This is something else
4636728
Press any key to continue
How does it work ??
Whats happenin?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|