C Syntax of return statement

C Syntax of the return statement

In C, the return statement is used to exit a function and return a value to the calling function. The syntax of the return statement is as follows:

return expression;
  • return: This is the keyword used to indicate the return statement.
  • expression: This is an optional expression that represents the value to be returned. The type of the expression must match the return type of the function.

Here's an example to illustrate the syntax:

int add(int a, int b) {
    int sum = a + b;
    return sum;
}

In the above example, the add function takes two integers as parameters, calculates their sum, and returns the result using the return statement.

Please let me know if you need further assistance!