int main() versus void main()

Pages: 123
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.
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!

Lol!
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.
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)
Or maybe it just breaks the universe.
I assume by nothing you mean 0.

Line 7 warning: division by zero;
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
There must be an exception for div by 0. Is there?
Last edited on
Using VC++ it throws an "exception" (not really an exception but you can catch it for some reason).
However:
return 0/42;
terminates program with status 0
Herp derp.
0/x=0
Herp derp.
0/x=0


yeah so what is:
x/0= ?
I don't get why it works one way but not the other.
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.
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.
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
I was talking about the program, not the function. :-)
I was responding to gcampton
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/
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()
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.
That's impossible, having void as a return value could not cause that problem...
Pages: 123