سؤال

I make a C program that returns char type value;

#include <stdio.h>
char *main(){
        return "## returned ##";
}

I get no message on standard out when I run it.

Any good way to see returned value on standard out without driver program?

هل كانت مفيدة؟

المحلول

in C, main() function always has to return an int.
That int value is returned to the operating system to indicate how did the program exit (successful termination, error during run) etc ....

In Windows, the value returned by main() is stored in a pseudo environment variable named errorlevel. to check for the its value you can simple use echo.

echo the program terminated with exit code %errorlevel%

a successful run is usually indicated by the value 0. *
that is why you see the traditional return 0; in all C Programs.

* As mentioned in the comment this is not a standard nor a requirement, it just the convention

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top