Home > Article > Backend Development > C function parameters and return values
Here we will see the different types of C functions based on return values and parameters.
Therefore, a function can take some parameters, or not take any parameters. Likewise, a function can return something and otherwise return nothing. Therefore, we can classify them into four types.
#include <stdio.h> void my_function() { printf("This is a function that takes no argument, and returns nothing."); } main() { my_function(); }
This is a function that takes no argument, and returns nothing.
This function does not accept any input parameters, and the return type is void. Therefore, it returns nothing.
#include <stdio.h> int my_function() { printf("This function takes no argument, But returns 50</p><p>"); return 50; } main() { int x; x = my_function(); printf("Returned Value: %d", x); }
This function takes no argument, But returns 50 Returned Value: 50
Here this function is not taking any input argument, but its return type is int. So this returns a value.
#include <stdio.h> void my_function(int x) { printf("This function is taking %d as argument, but returns nothing", x); return 50; } main() { int x; x = 10; my_function(x); }
This function is taking 10 as argument, but returns nothing
This function accepts an input parameter, but its return type is void. So it returns nothing.
#include <stdio.h> int my_function(int x) { printf("This will take an argument, and will return its squared value</p><p>"); return x * x; } main() { int x, res; x = 12; res = my_function(12); printf("Returned Value: %d", res); }
This function is taking 10 as argument, but returns nothing
The function here accepts any input parameter and returns a value.
The above is the detailed content of C function parameters and return values. For more information, please follow other related articles on the PHP Chinese website!