+ 1
Can I crash the program ?
Example: if the user inputs something i don't want he puts and i want the program to crash or exit
8 Respostas
+ 2
decent exit.... return 0;
crash exit ..... 0/0;
😊
0
Return 0;
from main.
It's the most ideal way to do it, always opt for it unless absolutely necessary to use a different method.
0
Yeah. You can always crash your code. For that, you need to expect the undesired values and always exit your program
0
That's not crashing... try to access memory you didn't allocate like 1000x. That should *really* force a proper operating system to end your program immediately.
0
Return 0; is not crashing, no. But he stated he wanted a crash ~or~ exit, which the safest and most efficient way would be to return 0 from main. Besides, I'm not sure why someone would want to cause an intentional crash over something much better.
0
So here you have a crashing solution :-) Actually posted a game in this forum a while ago that crashes with a 10% probability, if the uses loses the challenge. :-)
0
don't works so
maybe because i return twice ( at the end again)
else if(y != 1 && y != 0){
cout << "error" << endl;
return 0;
}
bonus question where did it return if i write return 0; ?
0
You return the "exit code" (the value behind the return in main) to the operating system.
Btw the error might be the "else" in front of the "if" this is only valid C++, if you already wrote an if clause.