Блог пользователя C137

Автор C137, история, 9 лет назад, По-английски

Hello everyone i was solving an easy problem using GNU C++ 4.9.2, but i kept getting runtime error!! the problem was so easy, and the code is simple, which made with mad!! however in the end /after about 3 hours of thinking/ i found that the problem was with the return statement, i was writing return 1; instead of return 0;

but i couldn't understand why this is a runtime error??? can anyone explain to me please...

With many thanks...

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Alternatively, you can write return EXIT_SUCCESS;, which is more obvious

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    according to standart it's ok to skip return statement in main function, this case will be interpreted as return 0;

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

or don't return anything!

»
7 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For more in-depth discussion:
what-should-main-return-in-c-and-c++
Hope it helps!

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

sps