Ask questions which are clear, concise and easy to understand.
Ask QuestionPosted by Rahul Verma 6 years, 8 months ago
- 0 answers
Posted by Ayush Sule 6 years, 8 months ago
- 0 answers
Posted by Siddharth Singh 6 years, 8 months ago
- 0 answers
Posted by Swmdwn Raja 6 years, 8 months ago
- 1 answers
Akshara Nair 6 years, 8 months ago
Posted by Akshara Nair 6 years, 8 months ago
- 4 answers
Posted by Rida Khan 6 years, 8 months ago
- 0 answers
Posted by Prity Barnwal 6 years, 8 months ago
- 1 answers
Posted by Dhiraj Bajaj 6 years, 8 months ago
- 0 answers
Posted by Ujjwal Kumar 6 years, 8 months ago
- 0 answers
Posted by Dharmesh Kumar 6 years, 8 months ago
- 1 answers
Cicil George 6 years, 8 months ago
Posted by Shabeel Idreesi 6 years, 8 months ago
- 0 answers
Posted by Amandeep Singh 6 years, 8 months ago
- 1 answers
Shivani Goyal 6 years, 8 months ago
Posted by Jasleen Kaur Dhami 4 years, 7 months ago
- 0 answers
Posted by Soumya Sharma 6 years, 8 months ago
- 0 answers
Posted by Taj Samra Taj Samra 6 years, 8 months ago
- 0 answers
Posted by Cool Guy 6 years, 8 months ago
- 1 answers
Arka Ghosal 6 years, 8 months ago
Posted by Pratiksha Mishra 6 years, 8 months ago
- 1 answers
Posted by Mehak Goyal 6 years, 8 months ago
- 0 answers
Posted by Saumya Pandey 3 years, 5 months ago
- 1 answers
Sia ? 3 years, 5 months ago
Call By Value | Call By Reference |
While calling a function, we pass values of variables to it. Such functions are known as “Call By Values”. | While calling a function, instead of passing the values of variables, we pass address of variables(location of variables) to the function known as “Call By References. |
In this method, the value of each variable in calling function is copied into corresponding dummy variables of the called function. | In this method, the address of actual variables in the calling function are copied into the dummy variables of the called function. |
With this method, the changes made to the dummy variables in the called function have no effect on the values of actual variables in the calling function. | With this method, using addresses we would have an access to the actual variables and hence we would be able to manipulate them. |
<pre> // C program to illustrate // call by value #include // Function Prototype void swapx(int x, int y); // Main function int main() { int a = 10, b = 20; // Pass by Values swapx(a, b); printf("a=%d b=%d\n", a, b); return 0; } // Swap functions that swaps // two values void swapx(int x, int y) { int t; t = x; x = y; y = t; printf("x=%d y=%d\n", x, y); } Output: x=20 y=10 a=10 b=20 </pre> | <pre> // C program to illustrate // Call by Reference #include // Function Prototype void swapx(int*, int*); // Main function int main() { int a = 10, b = 20; // Pass reference swapx(&a, &b); printf("a=%d b=%d\n", a, b); return 0; } // Function to swap two variables // by references void swapx(int* x, int* y) { int t; t = *x; *x = *y; *y = t; printf("x=%d y=%d\n", *x, *y); } Output: x=20 y=10 a=20 b=10 </pre> |
Thus actual values of a and b remain unchanged even after exchanging the values of x and y. | Thus actual values of a and b get changed after exchanging values of x and y. |
In call by values we cannot alter the values of actual variables through function calls. | In call by reference we can alter the values of variables through function calls. |
Values of variables are passes by Simple technique. | Pointer variables are necessary to define to store the address values of variables. |
Posted by Akshit Sharma 6 years, 8 months ago
- 1 answers
Akshit Sharma 6 years, 8 months ago
Posted by Yanini Krishna 6 years, 8 months ago
- 0 answers
Posted by Yashasvi Gautam 6 years, 8 months ago
- 1 answers
Posted by Thara Sakthi 6 years, 8 months ago
- 2 answers
Posted by Miya Hm 6 years, 8 months ago
- 0 answers
Posted by Gourav Bansal 6 years, 8 months ago
- 0 answers
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app