return type of functions in c



return is keyword of c. When the control reaches to the return keyword it immediately terminates the execution of that function and transfer the control to the calling function.
Syntax of return statement:
Here expression is optional which has indicated by [ ].
Example:

#includeprintf<stdio.h>
void dev();
int main(){
    printf("one\n");
    dev();
    printf("two\n");
    return 0;
}
void dev(){
    printf("three\n");
    return;
    printf("four\n");
}
Output:
one
three
two
Return type of function can be:
1. Primitive data type.

Primitive data types are: char, int, float, double, void

Examples:

a. function which is returning char data type

b. function which is returning int data type

c. function which is returning float data type

d. function which is returning double data type

e. function which is returning void data type

2. Derived data type.

Derived data types are: array, function, pointer

Examples:

a. Function which is returning array

b. function which is returning function

c. function which is returning pointer

3. User defined data type.

 User defined data types are: structure, union, enum

Examples:

a. Function which is returning structure

b. Function which is returning union

c. Function which is returning enum

No comments: