cout<<(int)main; => 4199392 Why??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

cout<<(int)main; => 4199392 Why???

#include <iostream> using namespace std; int main() { cout<<(int)main; return 0; }

19th Jan 2017, 4:05 AM
Herczeg Dániel
Herczeg Dániel - avatar
6 Answers
+ 4
Without paranthesis it writes 1, which cannot be memory adress, because the beginning of the RAM is reserved for jumping tables, stack etc. . With cast paranthesis I get 4199392 every time. If It were memory adress, it must be change depending of the content of RAM. You get this number if you run this code? If yes, than it is 100% that isn't an adress.
19th Jan 2017, 12:59 PM
Herczeg Dániel
Herczeg Dániel - avatar
+ 2
I think the int is 4byte=32 bit, and the numbers stored in two complement, so the biggest number is 2^31-1 which is not 4199392.
19th Jan 2017, 4:11 AM
Herczeg Dániel
Herczeg Dániel - avatar
+ 2
The memory adress of the function reference 'main', as you don't put parenthesis?
19th Jan 2017, 5:10 AM
visph
visph - avatar
+ 2
My guess is: The "main" name is only forbidden to use in global scope, in local scope you can declare a variable with name "main". I think it is a bug in the compiler. It must throw an error, because I try to wrote a value of a varible which is not initialized in local scope. The (int) is just a simple cast. I have no idea why I get back 4199392 instead of 1 if I use it...
19th Jan 2017, 1:12 PM
Herczeg Dániel
Herczeg Dániel - avatar
0
the maximum numeric value?
19th Jan 2017, 4:05 AM
CzarCoder
CzarCoder - avatar
0
I doubt it thou
19th Jan 2017, 4:06 AM
CzarCoder
CzarCoder - avatar