Declaration Functions magic
Jan 17

If a function has to return a value to the calling function,it is done through the return statement. It may be possible that a function does not return any value; only the control is transferred to the calling function.

Syntax

return (expression);

  • you can pass any number of arguments to a function but can return only one value at a time.

Example

return(5);  ,   return (x*y);     valid

return(2,3);   return(x,y);        invalid

  • If a function does not return anything,void specifier is used in the function declaration.
  • All the function’s type is by default is int i.e. a function return an integer value,if no type specifier is used in the function declaration.

Example

square(int n);

int square (int n);

Both above will return an integer value.

void square(int n);

it will not return anything.

  • A function can have many return statements. This thing happens when some condition based returns are required.

Example

if((i%2)==0)

return(0);

else

return(1);

  • With the execution of return statement,the control is transferred to the calling function with the value associated with it.

written by Shweta


Leave a Reply