Roast Beef
Roast Beef

Reputation: 25

Why can't I use EXIT_SUCCESS instead of 0 in the return statement in Visual Studio Code?

Why can't I use EXIT_SUCCESS instead of 0 in the return statement in Visual Studio Code? I get the error:

id "EXIT_SUCCESS" is not defined

#include <stdio.h>

int main(void)
{
    puts("Thanks for help");
    return EXIT_SUCCESS; /*problem*/
}

Upvotes: 1

Views: 319

Answers (2)

Adrian Mole
Adrian Mole

Reputation: 51825

The definitions of the EXIT_SUCCESS and EXIT_FAILURE macros are in the "stdlib.h" header file, so you need to #include <stdlib.h> in order to use them.

(Some compilers may implicitly include that header when you include "stdio.h" but you can't rely on that behaviour.)

Upvotes: 4

Lundin
Lundin

Reputation: 213799

Because EXIT_SUCCESS is located in stdlib.h and you didn't include it.

Upvotes: 1

Related Questions