Is there any alternative to return 0.?

*void main() should not b use as an alternative.

Recommended Answers

All 3 Replies

The only common alternative is standard a macro that evaluates to the same thing:

#include <stdlib.h>

int main(void)
{
    return EXIT_SUCCESS;
}

In C99 you can omit the return statement and 0 will be assumed:

int main(void)
{
    /* return 0; is implicit */
}

what is the use of return 0 in a program.
Is return 0 tells the pointer to reach to end of a program.

Is there any other alternative in which is reduced in characters than return 0.

what is the use of return 0 in a program.

It's the return value to the C runtime environment specifying success or failure. 0 means success and any non-zero value means failure in some implementation-dependent way.

Is return 0 tells the pointer to reach to end of a program.

The program ends regardless, since falling off the end of a function causes it to return. But if you return nothing prior to C99, what you're really doing is the equivalent of this:

int main(void)
{
    int rv;
    return rv;
}

Since rv is uninitialized, the value is unpredictable and trying to read it will invoke undefined behavior. The C runtime environment could very likely access the return value from main, which could wreak havoc because the value is indeterminate.

Is there any other alternative in which is reduced in characters than return 0.

No. Why are you so hell bent on reducing characters in such a trivial place?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.