Explain Call by Value in C language ?

Answer : In call by value, original value is not modified…

Explain Call by Value in C language ?

Call by value

  • In call by value, original value is not modified.
  • In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only.
  • It will not change the value of variable inside the caller method such as main().

Sample Code

[pastacode lang=”c” manual=”%23include%3Cstdio.h%3E%0Avoid%20change(int%20num)%20%0A%7B%20%20%20%20%0A%20%20%20%20printf(%22Before%20adding%20value%20inside%20function%20num%3D%25d%20%5Cn%22%2Cnum)%3B%20%20%20%20%0A%20%20%20%20num%3Dnum%2B100%3B%20%20%20%20%0A%20%20%20%20printf(%22After%20adding%20value%20inside%20function%20num%3D%25d%20%5Cn%22%2C%20num)%3B%20%20%20%20%0A%7D%20%20%20%20%0Aint%20main()%20%0A%7B%20%20%20%20%0A%20%20%20%20int%20x%3D100%3B%20%20%20%20%0A%20%20%20%20printf(%22Before%20function%20call%20x%3D%25d%20%5Cn%22%2C%20x)%3B%20%20%20%20%0A%20%20%20%20change(x)%3B%2F%2Fpassing%20value%20in%20function%20%20%20%20%0A%20%20%20%20printf(%22After%20function%20call%20x%3D%25d%20%5Cn%22%2C%20x)%3B%20%20%20%20%0A%20%20%20%20return%200%3B%20%20%0A%7D%20″ message=”” highlight=”” provider=”manual”/]

Output

[pastacode lang=”c” manual=”Before%20function%20call%20x%3D100%20%0ABefore%20adding%20value%20inside%20function%20num%3D100%0AAfter%20adding%20value%20inside%20function%20num%3D200%0AAfter%20function%20call%20x%3D100″ message=”” highlight=”” provider=”manual”/]
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like