C/return type in c
Expert: Zlatko - 5/19/2010
Questioni am confused with return types in c programing,use of arguments i.e. parameter of function is hanging me, how to solve these problems?
AnswerHello Deepak
A function performs a task. If the task is to calculate a value, the function must return the value. The return type describes the value. It specifies if the value is an integer, a floating point number, or something else.
A function may need input for its operations. The input is passed in as parameters.
That is the way most functions work, and if you are a beginner, you should use that model.
For example, consider a function that squares a number. The number is passed as a parameter, and the result is returned.
Lets say the input parameter is an integer. Then the output will be an integer too.
The function looks like this.
int calculate_square(int input)
{
return input * input;
}
The return type is written before the function name. The parameters are written after the function name.
When calling the function, you must assign the result to some value like this.
int result;
result = calculate_square(5);
You can expect result to get 25.
You did not really explain what you are confused about. Maybe my answer will let you ask more specific questions.
Best regards
Zlatko