Return Keyword
In C programming, the 'return' keyword is used to exit a function and return a value back to the calling function.
It is also used to terminate the execution of a function prematurely.
Here's an example of using the 'return' keyword:
int add(int a, int b) {
return a + b;
}
int result = add(5, 3);
printf("The result is: %d\n", result);
In this example, the 'return' keyword is used to return the sum of 'a' and 'b' back to the calling function.
The function 'add' takes two integers as parameters, performs the addition operation, and returns the result.
The returned value is then assigned to the variable 'result' and printed using 'printf'.
The 'return' keyword can be used with or without a value. When used without a value, it simply exits the function.
When used with a value, it returns that value to the calling function.
The data type of the returned value must match the return type declared in the function signature.