Posts

Showing posts with the label Call by Reference

Call by Value and Call by Reference Method in C Language (C भाषा में कॉल बाय वैल्यू और कॉल बाय रिफरेन्स मेथड)

In C language, arguments can be passed to a function in different ways. Two commonly taught methods are Call by Value and Call by Reference (using pointers). These methods determine how a function receives and works with the values of variables. C भाषा में Function को Arguments अलग-अलग तरीकों से पास किए जा सकते हैं। दो प्रमुख तरीके Call by Value और Call by Reference (Pointers का उपयोग करके) हैं। ये तरीके निर्धारित करते हैं कि Function variables की values को किस प्रकार प्राप्त और उपयोग करता है। 1. Call by Value Method (कॉल बाय वैल्यू मेथड) In Call by Value method, the values of actual arguments are copied into the formal arguments. Any changes made to the formal arguments inside the function do not affect the original variables. Call by Value Method में Actual Arguments की values को Formal Arguments में कॉपी किया जाता है। Function के अंदर Formal Arguments की values में किए गए बदलाव Original Variables को प्रभावित नहीं करते हैं। Characteristics of Call by Value (विशेषताएँ) The values of a...

C Program to Swap Values of Two Variables Using Function (Call by Reference) फंक्शन (कॉल बाय रिफरेन्स) का उपयोग करके दो वेरिएबल की वैल्कयू स्वैप करने का C प्रोग्राम

In C language, we can swap the values of two variables using pointers. The addresses of the actual arguments are passed to the function, allowing the function to modify the original variables. C भाषा में Pointers का उपयोग करके दो variables की values को swap किया जा सकता है। इसमें actual arguments के addresses function को पास किए जाते हैं, जिससे function original variables की values को बदल सकता है। C Program #include <stdio.h> void swap(int *x, int *y); int main(void) { int a, b; printf("Enter two integer numbers:\n"); scanf("%d %d", &a, &b); printf("Before swapping: A = %d and B = %d\n", a, b); swap(&a, &b); printf("After swapping: A = %d and B = %d\n", a, b); return 0; } void swap(int *x, int *y) { int z; z = *x; *x = *y; *y = z; } Output Enter two integer numbers: 10 20 Before swapping: A = 10 and B = 20 After swapping: A = 20 and B = 10 Explanation (व्याख्या) Two integer numbers...