Recursion return 1 statement [closed]

In this statement, you get number, use it as address in memory, which is most likely invalid.

file.write((char*)num, sizeof(num));

If you want to write num in binary representation, you should get its address first:

file.write(reinterpret_cast<char*>(&num), sizeof(num));

Note the ampersand which is unary operator for getting addresses. I have also used reinterpret_cast which is C++ type conversion for such cases. C-style conversion may hide errors (but reinterpret_cast is also valid for int->* conversion).

P.S. void main() is an invalid prototype of main. It should return int at least.

Browse More Popular Posts

Leave a Comment