1
#include "iostream"

using namespace std;

int main(int argc, char const *argv[])
{
    int n=100000;
    int cost=6;
    for (int i = 1; i <= n; ++i)
    {
        cout<<cost<<endl;
    }
    return 0;
}

The above program when compiled and run on ideone.com (online g++ compiler which uses SPOJ compiler) gives a Runtime Error. When the cout line is commented out, the program runs successfully. Can someone point out the reason for the same?

4
  • 1
    There is nothing wrong with that code (other than it should be <iostream>). Commented May 27, 2014 at 7:08
  • 3
    Maybe there is a limit at ideone.com on the maximum number of bytes your program is allowed to print. Change n to something smaller (10000, 1000, 100 or 10) and see if your problem is solved. Commented May 27, 2014 at 7:09
  • 1
    It worked fine for me on compileonline.com/compile_cpp_online.php Commented May 27, 2014 at 7:12
  • 1
    It is always a good idea to add the error message to your question. Commented May 27, 2014 at 7:12

2 Answers 2

5

As pts pointed it out in his comment, ideone.com has a limit to the number of bytes you can print out. If you change n to 10000, the code runs fine.

The maximum n value that won't give compile error is 2^15 = 32768.

If you look carefully, you can see it terminates with signal:25, SIGXFSZ. You can take a look at this page to learn what signals mean.

SIGXFSZ 25 File size limit exceeded (4.2 BSD)

Sign up to request clarification or add additional context in comments.

Comments

0

Theoretically this could overflow if int is two bytes on your platform (which the standard allows). But most likely the error is due to output size limits at ideone.com. Do learn to interpret error messages: they are your friends and are as least as important as desired program output.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.