int main() versus void main()

Pages: 123
Feb 22, 2010 at 8:00pm
Oh, I forgot about operator preference.

Tbh, the script above (three line one) is what I used to build that; so I know it evaluates to zero.
Feb 22, 2010 at 8:06pm
wait a minute... I didn't actually compile it... but there's no way...

*does math*

Apparently I suck at math.

For some reason I didn't make the connection that 16 + 8 = 24

I lose!

Feb 22, 2010 at 8:24pm
Lol!
Feb 22, 2010 at 11:35pm
wtf. You guys fail at math.

return 42/42; // hhgttg beats your silly XOR

This evaluates to 1, not zero

Bahahahaha, WOW, well it was 1:03am when I posted that....
I might as well just put return 42; then eh.
Feb 23, 2010 at 1:27am
This returns nothing:
1
2
3
4
5
6
7
8
#include <iostream>
int main()
  {
  int z = 0;
  std::cout << "Hello world!\n";

  return 42/z;
  }

:0)
Feb 23, 2010 at 1:28am
Or maybe it just breaks the universe.
Feb 23, 2010 at 1:33am
I assume by nothing you mean 0.

Line 7 warning: division by zero;
Feb 23, 2010 at 1:36am
weird, I just did return 42/0; got a warning for dividing by 0;
then did:
1
2
int a=0;
return 42/a;

and it compiles fine

running it however...
Process terminated with status -1073741676


return 42/0;
gives the same status. -1073741676

However:
return 0/42;
terminates program with status 0
Last edited on Feb 23, 2010 at 1:41am
Feb 23, 2010 at 1:39am
There must be an exception for div by 0. Is there?
Last edited on Feb 23, 2010 at 1:39am
Feb 23, 2010 at 1:41am
Using VC++ it throws an "exception" (not really an exception but you can catch it for some reason).
Feb 23, 2010 at 2:27am
However:
return 0/42;
terminates program with status 0
Herp derp.
0/x=0
Feb 23, 2010 at 2:35am
Herp derp.
0/x=0


yeah so what is:
x/0= ?
I don't get why it works one way but not the other.
Feb 23, 2010 at 2:45am
Assuming x does not equal zero, of course. 0/0 is undefined, as is any value / 0. That's just how it is.
Based on a limit of any number / x, with x approaching zero, the limit should reach infinity. However, that doesn't define divbyzero.
Feb 23, 2010 at 2:51am
Technically, it does return something -- just what is returned depends on your operating system. Many have a way of indicating program failure, such as an abort due to a hardware exception.
Feb 23, 2010 at 3:40am
Based on a limit of any number / x, with x approaching zero, the limit should reach infinity.
The proper way to say is: the limit of |a|/x is +∞ as x approaches 0 from the right, and -∞ as x approaches 0 from the left.

Technically, it does return something
I was talking about the function, not the program.
Last edited on Feb 23, 2010 at 6:03am
Feb 23, 2010 at 4:26am
I was talking about the program, not the function. :-)
I was responding to gcampton
Feb 23, 2010 at 8:31am
There must be an exception for div by 0. Is there?

CPU exception 0x00 is "Division by zero" error; see chapter 6, volume 3a: http://www.intel.com/products/processor/manuals/
Feb 23, 2010 at 10:11am
i made a program using void main() that features looping on a XP, and tried to run it on a win7, but after 2-3 loopings the program closes, then i changed the void main() into int main() with return 0; and now it works fine and i may loop it as much as i want w/o closing it itself

so yeah, dont use void main()
Feb 23, 2010 at 12:21pm
i made a program using void main() [...] but after 2-3 loopings the program closes
I seriously doubt it has anything to do with it.
Feb 23, 2010 at 1:03pm
That's impossible, having void as a return value could not cause that problem...
Pages: 123