This blog is under construction

Saturday, 12 May 2012

return Statement

return statement is used to return program control from calling function to called function. The outcome from the called function will be sent to the calling function through the return statement.  Only one value can be returned using return statement. Value returned from the called function can be collected using a variable in calling function.  Below is the general form of return statement.

return return_value;

In case of void function, we can use return statement without return value as shown below.

return;

Example C program to illustrate return Statement:
 
  #include <stdio.h>
  int multiply(int, int);

  int main() {
        int a, b, res;
        printf("Enter two number to multiply:\n");
        scanf("%d%d", &a, &b);
        // return value of multiply() function is stored in variable res
        res = multiply(a, b);
        printf("Output: %d\n", res);
        return 0;
  }

  int multiply(int a, int b) {
        return (a * b);
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter two number to multiply:
  10 20
  Output: 200


1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete