468,167 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,167 developers. It's quick & easy.

What is the call by value in function?

what is the call by value in function??
Mar 5 '13 #1
3 3854
divideby0
131 128KB
Call by value passes a copy of a variable into a function. The copy can be modified within the function, but the original value isn't changed.

Expand|Select|Wrap|Line Numbers
  1. void foo(int x)
  2. {
  3.    x = 5; // modification is local only
  4. }
  5.  
  6. ...
  7.  
  8. int y = 0;
  9. foo(y); // upon return, y is still 0
  10.  
Mar 5 '13 #2
Sherin
77 64KB
The call by value the actual arguments are copied to the formal arguments, hence any operation performed by function on arguments doesnít affect actual parameters. Lets take an example to understand this:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int increment(int var)
  3. {
  4.     var = var+1;
  5.     return var;
  6. }
  7.  
  8. int main()
  9. {
  10.    int num1=10;
  11.    int num2 = increment(num1);
  12.    printf("num1 value is: %d", num1);
  13.    printf("\nnum2 value is: %d", num2);
  14.  
  15.    return 0;
  16. }
Feb 25 '21 #3
prasanthp
2 2Bits
In the call by value method, we pass a copy of the parameter is passed to the functions. For these copied values a new memory is assigned and changes made to these values do not reflect the variable in the main function.
Mar 18 '21 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by domeceo | last post: by
5 posts views Thread by phil_gg04 | last post: by
2 posts views Thread by laredotornado | last post: by
2 posts views Thread by sushil | last post: by
8 posts views Thread by Olov Johansson | last post: by
3 posts views Thread by Beta What | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.