whats happening here?

hey people,
recently i was found out something interesting but couldn't find any explanation to it!, so please help.

can u explain whats happening here?

1.

cout<<cout;

output: 0x4740c4

2.

cout<<(cin>>some_variable);

upon entering any value
output: 0x474028


3.

cout<<(cout<<1024);

output: 10240x4740c4

My interpretation is...

the operator << and >> is overloaded such that when cout or cin object is passed it prints the address (of something, but what address is it?)

Its just my interpretation... It may be absolutely wrong!



thanks in Advance! :)
Depending on what is overloading them the operators can be doing anything. If you're just using iostream I'd say it's the address of the standard output device.

cout<<(cin>>some_variable); Following my logic above this would be the standard Input device, i.e. the Keyboard.

cout<<(cout<<1024); This would be the Standard Output again with 1024 tacked onto the beginning.
cin and cout both have implicit casts to void*:

http://www.cplusplus.com/reference/iostream/ios/operator_voidpt/

Per that page, the pointer it gives you is more or less useless. It will be null if the last operation failed, or non-null if the last operation was a success.

With that in mind...
1
2
3
4
5
6
7
8
9
10
//this
cout<<(cin>>foo);

// is the same as this:
cin >> foo;
cout << cin;

// is the same as this:
cin >> foo;
cout << (void*)cin;
Topic archived. No new replies allowed.