Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is the main role of return 0 in c language?

–7 votes
asked Feb 17, 2021 by lavanya kondisetty 15 (120 points)

3 Answers

+2 votes
answered Feb 18, 2021 by Peter Minarik (84,720 points)

The return statement tells the running function that it should stop running and give back execution to the called. While doing that a value is returned (for non-void type functions) indicating the result of the function.

Example: provide the calculated value of a function

static int Add(int a, int b)
{
    return a + b;
}

Example: leave a function early

static void PrintIfNonEmpty(const char * name)
{
    if (name == NULL || name[0] == '\0') // if the pointer is not set or the name is an empty string
        return;
    
    printf("Your name is %s.", name);
}

For details, please read https://docs.microsoft.com/en-us/cpp/c-language/return-statement-c

0 votes
answered Mar 2, 2021 by Vishal Singh (140 points)
If you make function using int then then integer has atleast  one returning value.
0 votes
answered Mar 9, 2021 by Arun (140 points)
If you are asking why there is usually are return 0 at the end of the default main function implementation like the following:

int main()
{
    printf("Hello World");

    return 0;
}

The answer by Peter explains that main is returning a value of 0. In most programs, returning 0 means that everything worked fine. If you want you can return a non-zero value and that can be retrieved by the person calling the executable (e.g. a command-line call) to decide what to do. Here's a set of common return values:
 

https://www.tutorialspoint.com/batch_script/batch_script_return_code.htm
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...