---
title: "Call by Value and Call by Reference"  
description: "Call by Value and Call by Reference"  
author: "Anonymous User"  
published: 2018-07-17  
updated: 2018-07-17  
canonical: https://www.mindstick.com/forum/34619/call-by-value-and-call-by-reference  
category: "education"  
tags: ["database design", "education"]  
reading_time: 2 minutes  

---

# Call by Value and Call by Reference

[Explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) Call by [Value and Call by Reference](https://www.mindstick.com/interview/2702/what-is-call-by-value-and-call-by-reference) through [stack](https://www.mindstick.com/blog/301746/why-is-stack-overflow-so-important-for-developers) in [data structure](https://www.mindstick.com/blog/11221/simple-way-to-learn-dynamic-data-structure-in-c-language) ?

## Replies

### Reply by Prakash nidhi Verma

Call by [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages):

the called function creates a new set of variables in stack is called call by value whch is copies the values of the arguments into method.

```
void swap(int x, int y) {
     int z;
     z = x;
     x = y;
     y = z;
     printf("Swapped values are a = %d and b = %d", x, y);
 }

int main (int argc, char *argv[])
{
     int a = 10, b = 6;
     printf("Original values are a = %d and b = %d", a, b);
     swap(a, b);
     printf("The values after swap are a = %d and b = %d", a, b);
}
```

- push value of b

- push value of a

- save return address

- call function

Call by [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php):

instead of passing values to the function by a pointers to the original variables are passed this method known as call by reference method.

```
void swap(int *x, int *y) {
     int z;
    z = *x;
     *x = *y;
     *y = z;
     printf("Swapped values are a = %d and b = %d", *x, *y);
}
int main (int argc, char *argv[])
{
     int a = 10, b = 6;
     printf("Original values are a = %d and b = %d", a, b);
     swap(&a, &b);
     printf("The values after swap are a = %d and b = %d", a, b);
 }
```

- push address of b

- push address of a

- save return address

- call function


---

Original Source: https://www.mindstick.com/forum/34619/call-by-value-and-call-by-reference

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
