C++ brainteaser

Today one of my friends came to my room to ask a doubt in C++

The he came up with was a very simple one but had a very interesting solution and exhibited the difference in the computations of 32 bit and 64 bit processors and had literally taken us to a stand still

The Code was:

..

void main()

{

int i = 0;

i = 400*400/400;

cout<<i;

getch();

}

This was the piece of code, and would like as many people to think about it and give answers with reasons.

9 thoughts on “C++ brainteaser

    1. If you use gcc, then also a c program requests for a return value, however can you give me the reference where I can find that returning a value is must for C++ I will be greatful and your answer is write

      Like

      1. You are right that the main function doesn’t require a “return something;” statement. Still, main needs to be declared with an int as return type, not void. This should be covered in just about any good book about C++ that was published after 1998. When in doubt, check the ISO/IEC 14882:2003 standard.

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.