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?

–8 votes
asked Feb 17 by lavanya kondisetty 15 (100 points)

1 Answer

+2 votes
answered Feb 18 by Peter Minarik (19,180 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
    printf("Your name is %s.", name);

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

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.