Parameter Passing: Call by Value (Copying Values) Notes in Hindi & English : कॉल बाई वैल्यू: मान की कॉपी पास करना और मूल चर में अपरिवर्तन और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Parameter Passing: Call by Value (Copying Values) (कॉल बाई वैल्यू: मान की कॉपी पास करना और मूल चर में अपरिवर्तन) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Call by Value is C's native parameter-passing mechanism in which actual argument values are copied into separate formal parameters on the callee's stack frame. Because the callee operates exclusively on private copies, changes to formal parameters never alter the caller's original variables.

अध्याय सार: कॉल बाई वैल्यू (Call by Value) C की डिफ़ॉल्ट पैरामीटर पासिंग प्रणाली है जिसमें कॉल करते समय वास्तविक मानों की प्रतियाँ (Copies) फंक्शन के फॉर्मल पैरामीटर्स में बनती हैं। चूंकि फंक्शन केवल इन निजी प्रतियों पर कार्य करता है, इसलिए मूल वेरिएबल्स में कोई परिवर्तन नहीं होता।

Parameter Passing: Call by Value (Copying Values): Detailed Notes & Architecture (कॉल बाई वैल्यू: मान की कॉपी पास करना और मूल चर में अपरिवर्तन)

1. Value-Copying Semantics & Caller Immutability (मान कॉपी करने की प्रक्रिया व मूल डेटा सुरक्षा)

[EN] ISO C strictly passes every argument by value: the caller evaluates each expression and copies its value into the callee's newly allocated formal parameter slot. Because caller variables and callee parameters reside at completely different stack addresses, modifying 'a = 99;' inside the callee touches only its local copy. Upon return, that copy is destroyed while the caller's original variables remain untouched.

[HI] ISO C में सभी आर्गुमेंट्स स्वाभाविक रूप से कॉल बाई वैल्यू से ही पास होते हैं: कॉल करने पर हर एक्सप्रेशन का मान कॉली के नए स्टैक फ्रेम में कॉपी किया जाता है। दोनों के मेमोरी पते अलग होने के कारण फंक्शन में 'a = 99;' करने से केवल स्थानीय कॉपी बदलती है और return के बाद कॉलर के मूल वेरिएबल बिल्कुल अपरिवर्तित रहते हैं।

2. Advantages, Flexibility & Large-Struct Overhead (लाभ, लचीलापन व बड़े स्ट्रक्चर का ओवरहेड)

[EN] Call by Value protects caller state from accidental mutation and permits passing literals ('sq(5)'), constants, and arithmetic expressions ('sq(x + y)') without requiring addressable variables. However, passing a large struct (such as a 4 KB buffer inside a struct) by value copies every byte onto the stack on each call, wasting CPU time and risking stack overflow in deep recursion; passing a 'const struct S*' pointer eliminates that copy.

[HI] कॉल बाई वैल्यू मूल डेटा को अनपेक्षित बदलावों से बचाता है और सीधे स्थिरांक (5) या अभिव्यक्ति (x + y) पास करने की सुविधा देता है। परंतु बहुत बड़े struct को बाय वैल्यू पास करने पर उसके सारे बाइट्स स्टैक पर कॉपी होते हैं जिससे समय व मेमोरी खर्च होती है—इस स्थिति में 'const struct S*' पॉइंटर उपयोग करना बेहतर है।

3. Why Naive Swap Fails & Returning Single Results (स्वैपिंग विफलता का कारण व मान लौटाना)

[EN] A classic beginner mistake is writing 'void swap(int a, int b) { int t = a; a = b; b = t; }' and expecting swap(x, y) to exchange x and y in main(). Inside swap, copies a and b swap values, then disappear at return leaving x and y unchanged. To update caller state under pure Call by Value, a function must explicitly return the computed value (e.g., 'x = square(x);') or pass pointer addresses.

[HI] प्रारंभिक प्रोग्रामर अक्सर 'void swap(int a, int b)' लिखकर swap(x, y) से मूल x और y बदलने की अपेक्षा करते हैं, जो विफल रहता है क्योंकि केवल स्थानीय कॉपियाँ a और b ही आपस में बदलकर नष्ट हो जाती हैं। शुद्ध कॉल बाई वैल्यू में नया मान पाने के लिए फंक्शन से return लेकर कॉलर में असाइन करना (x = square(x);) या पॉइंटर पास करना आवश्यक है।

4. Pointer-by-Value & Struct-Wrapped Array Subtleties (पॉइंटर-बाई-वैल्यू तथा स्ट्रक्चर में बंद एरे का नियम)

[EN] Passing a pointer variable 'ptr' into 'void f(int *p) { p = NULL; }' STILL uses Call by Value: 'p' gets a copy of the address inside 'ptr', so setting 'p = NULL' does not alter 'ptr' in main() (only '*p = 0' modifies the pointed integer). Similarly, while a bare array decays to a pointer passed by value, wrapping an array inside a struct ('struct Box { int arr[10]; };') and passing the struct copies all 10 integers by value!

[HI] किसी पॉइंटर 'ptr' को 'void f(int *p) { p = NULL; }' में भेजना भी कॉल बाई वैल्यू ही है, क्योंकि p में ptr के पते की कॉपी आती है—अतः 'p = NULL' करने से main() का ptr नहीं बदलता। इसी प्रकार साधारण एरे डिके होकर पता पास करता है, किंतु यदि एरे को किसी struct के अंदर बंद करके struct को बाय वैल्यू पास किया जाए, तो पूरा एरे कॉपी होकर मूल एरे को सुरक्षित रखता है।

Syntax, Formula & Technical Example (Parameter Passing: Call by Value (Copying Values))

#include <stdio.h>
void attemptSwap(int a, int b) { // Receives local stack copies
    int temp = a; a = b; b = temp;
}
int main(void) {
    int x = 10, y = 25;
    attemptSwap(x, y);           // Original x, y remain untouched
    printf("x=%d, y=%d\n", x, y); // Output: x=10, y=25
    return 0;
}

Parameter Passing: Call by Value (Copying Values) Quick Reference & Comparison Table

Call by Value PropertyBehavior in CKey Exam / Practical Note
Transfer MechanismCopies actual argument value into parameterOriginal caller variables never change directly
Memory AddressesCaller and callee hold separate stack addressesPrevents accidental side effects across functions
Argument FlexibilityAccepts literals, variables, and expressionsNo addressable memory lvalue needed at call
Large Struct ImpactCopies entire byte footprint onto call stackSlow for big structs; prefer const pointer

Parameter Passing: Call by Value (Copying Values) Top 20 Bilingual MCQs with Answers

Q1. What occurs internally during Call by Value in C?

(C में कॉल बाई वैल्यू के दौरान आंतरिक रूप से क्या होता है?)

(A) Global pointers replace local parameters

(B) Values of actual arguments are copied into distinct formal parameters in the callee's stack frame

(C) Caller variables are locked read-only in hardware

(D) Memory addresses of variables are shared directly

Correct Answer: (B)

[EN] Every formal parameter receives an independent stack copy initialized with the value of its corresponding argument.

[HI] प्रत्येक फॉर्मल पैरामीटर को कॉली के स्टैक फ्रेम में अलग स्थान मिलता है जिसमें एक्चुअल मान की कॉपी रखी जाती है।

Q2. Which parameter passing mechanism is natively built into standard ISO C?

(मानक ISO C में इनमें से कौन सी पैरामीटर पासिंग विधि अंतर्निहित (Natively Supported) है?)

(A) Call by Reference via & only

(B) Call by Value-Result

(C) Call by Name

(D) Call by Value only

Correct Answer: (D)

[EN] ISO C passes all arguments by value—even pointers! Pointer-based Call by Reference passes an address by value.

[HI] मानक C में मूल रूप से केवल कॉल बाई वैल्यू ही होती है; कॉल बाई रेफरेंस भी पते को बाय वैल्यू पास करके लागू किया जाता है।

Q3. If main() sets 'int x = 50;' and calls 'update(x);' where 'void update(int a) { a = 100; }', what is x afterward?

(यदि main() में 'int x = 50;' हो और 'void update(int a) { a = 100; }' को update(x) से कॉल करें, तो बाद में x का मान क्या होगा?)

(A) Undefined

(B) 150

(C) 100

(D) 50

Correct Answer: (D)

[EN] a = 100 modifies only the local parameter copy inside update(); main()'s x remains 50.

[HI] a = 100 केवल update() की स्थानीय कॉपी को बदलता है, जिससे main() का मूल x 50 ही बना रहता है।

Q4. What prints in: void swap(int a, int b) { int t=a; a=b; b=t; } int main() { int x=5, y=9; swap(x, y); printf("%d %d", x, y); }?

('void swap(int a, int b) { int t=a; a=b; b=t; }' को swap(x, y) से कॉल करने पर main में क्या प्रिंट होगा?)

(A) 9 9

(B) 9 5

(C) 5 5

(D) 5 9

Correct Answer: (D)

[EN] Call by Value swaps only the temporary copies a and b, leaving x and y in main completely unchanged.

[HI] कॉल बाई वैल्यू में केवल a और b की स्थानीय कॉपियाँ बदलती हैं, अतः मुख्य प्रोग्राम में 5 9 ही प्रिंट होगा।

Q5. In main(), 'int a = 7;' calls 'void f(int a)'. Inside f, how does &a compare to &a inside main()?

(main() से 'void f(int a)' को f(a) से कॉल करने पर f के अंदर &a और main के अंदर &a कैसे होते हैं?)

(A) They are always the exact same memory address

(B) Compilation fails due to shadowing

(C) Only &a inside main is valid

(D) They are two different stack memory addresses

Correct Answer: (D)

[EN] Even with identical names, formal parameters reside in the callee's stack frame at a distinct address.

[HI] एक जैसा नाम होने पर भी दोनों अलग-अलग स्टैक फ्रेम में होते हैं, इसलिए दोनों के मेमोरी पते (&a) भिन्न होते हैं।

Q6. Why can Call by Value accept 'calc(10 + 5)' while pointer Call by Reference rejects 'calc(&(10 + 5))'?

(कॉल बाई वैल्यू 'calc(10 + 5)' को स्वीकार कर लेता है जबकि पॉइंटर कॉल बाई रेफरेंस 'calc(&(10 + 5))' को क्यों अस्वीकार करता है?)

(A) Call by Value copies an rvalue directly, whereas & requires an addressable memory lvalue

(B) 10 + 5 is treated as a float

(C) Arithmetic expressions cannot exist inside calls

(D) Pointers cannot hold sums larger than 10

Correct Answer: (A)

[EN] Temporary expression results have no stable memory address for the & operator, but their value can easily be copied.

[HI] अभिव्यक्ति (10 + 5) का कोई स्थायी मेमोरी पता नहीं होता जिस पर '&' लगाया जा सके, पर उसका मान आसानी से कॉपी हो सकता है।

Q7. Trace output: void zeroPtr(int *p) { p = NULL; } int main() { int x=5, *ptr=&x; zeroPtr(ptr); printf("%d", *ptr); }

(कोड 'void zeroPtr(int *p) { p = NULL; }' में zeroPtr(ptr) के बाद *ptr प्रिंट करने पर क्या आएगा?)

(A) Segmentation fault (NULL dereference)

(B) Compile error

(C) 0

(D) 5

Correct Answer: (D)

[EN] ptr is passed by value into p; setting p = NULL modifies only the local copy p, leaving ptr still pointing to x.

[HI] यहाँ ptr की कॉपी p में गई है; p = NULL करने से केवल स्थानीय p शून्य होता है, main का ptr अब भी x की ओर इशारा कर 5 प्रिंट करेगा।

Q8. If 'struct Arr { int v[3]; };' is passed by value to 'void chg(struct Arr s) { s.v[0] = 99; }', what happens to caller's s1.v[0] (initially 1)?

(यदि 'struct Arr { int v[3]; };' को बाय वैल्यू पास कर फंक्शन में s.v[0] = 99 करें, तो कॉलर के मूल s1.v[0] (मान 1) पर क्या असर होगा?)

(A) Caller's s1.v[0] becomes 99

(B) Structs cannot contain arrays in C

(C) Compile error

(D) Caller's s1.v[0] remains 1 because the entire struct and its array are copied

Correct Answer: (D)

[EN] Passing a struct by value copies every member byte-for-byte—including fixed-size arrays wrapped inside the struct!

[HI] struct को बाय वैल्यू पास करने पर उसके अंदर मौजूद पूरा एरे भी कॉपी हो जाता है, अतः मूल s1.v[0] का मान 1 ही रहेगा।

Q9. During recursive execution of 'int fact(int n)', what keeps each recursive call's 'n' isolated from deeper calls?

('int fact(int n)' के रिकर्सिव निष्पादन में प्रत्येक कॉल के 'n' को आगे के कॉल्स से कौन अलग रखता है?)

(A) The compiler creates global arrays n[100]

(B) static keyword automatically saves n

(C) Each call gets its own independent stack copy of n via Call by Value

(D) n is stored in read-only ROM

Correct Answer: (C)

[EN] Call by Value allocates a fresh formal parameter 'n' inside every new stack frame pushed during recursion.

[HI] कॉल बाई वैल्यू प्रत्येक रिकर्सिव कॉल के लिए स्टैक पर 'n' की एक नई स्वतंत्र कॉपी बनाता है।

Q10. What is a major drawback of passing a 10 KB struct strictly by value in frequent function calls?

(बार-बार कॉल होने वाले फंक्शन में 10 KB के बड़े struct को बाय वैल्यू पास करने की मुख्य हानि क्या है?)

(A) It converts the struct into a linked list

(B) Every call copies all 10 KB onto the stack, degrading speed and risking stack overflow

(C) The struct members become read-only globally

(D) C automatically truncates structs over 64 bytes

Correct Answer: (B)

[EN] Duplicating thousands of bytes per call wastes CPU cycles and stack frames; passing a const pointer copies just 4 or 8 bytes.

[HI] हर कॉल पर पूरे 10 KB डेटा की कॉपी स्टैक पर बनने से प्रदर्शन धीमा होता है और स्टैक ओवरफ्लो का खतरा बढ़ता है।

Q11. Why is Call by Value safer than pointer passing when a function only needs to read a primitive variable?

(जब किसी फंक्शन को केवल एक सामान्य वेरिएबल पढ़ना हो, तो पॉइंटर के बजाय कॉल बाई वैल्यू अधिक सुरक्षित क्यों है?)

(A) It guarantees caller data cannot be accidentally overwritten inside the function

(B) It runs without using any stack memory

(C) It bypasses type checking

(D) It disables integer overflow automatically

Correct Answer: (A)

[EN] Data isolation enforces immutability for the caller's original variable without needing const guards.

[HI] कॉल बाई वैल्यू सुनिश्चित करता है कि फंक्शन गलती से भी कॉलर के मूल वेरिएबल का मान नहीं बदल सकता।

Q12. How can a function using pure Call by Value (no pointers) update one variable 'x' in main()?

(बिना पॉइंटर लिए केवल शुद्ध कॉल बाई वैल्यू का उपयोग करके main() के एक वेरिएबल 'x' का मान कैसे अपडेट किया जा सकता है?)

(A) Use global void parameters

(B) Return the new value from the function and assign it: x = modify(x);

(C) Use break inside the function

(D) Declare formal parameter static

Correct Answer: (B)

[EN] Returning the computed value allows the caller to capture and overwrite x explicitly.

[HI] फंक्शन से नया मान return करके कॉलर में पुनः असाइन (x = modify(x);) किया जा सकता है।

Q13. When an array 'int a[5]' is passed to 'void f(int x[])', why can f modify a[0] even though C uses Call by Value?

(C में कॉल बाई वैल्यू होने के बावजूद 'int a[5]' को 'void f(int x[])' में पास करने पर f द्वारा a[0] क्यों बदल जाता है?)

(A) C copies the array back automatically after return

(B) Array name 'a' decays to address &a[0], and that pointer address is copied by value into x

(C) Arrays live in static register memory

(D) Arrays are an exception that uses C++ references

Correct Answer: (B)

[EN] Copying the base address by value gives the callee direct pointer access to the caller's array elements.

[HI] एरे का नाम पहले तत्व के पते (&a[0]) में डिके होता है और वह पता बाय वैल्यू x में कॉपी होकर मूल एरे को एक्सेस करने देता है।

Q14. If global 'int g = 5;' exists and 'void fn(int g) { g = 20; }' is called via 'fn(g);', what is global g afterward?

(यदि ग्लोबल 'int g = 5;' हो और 'void fn(int g) { g = 20; }' को fn(g) से कॉल किया जाए, तो बाद में ग्लोबल g क्या होगा?)

(A) 0

(B) Compile error

(C) 5 (global g is shadowed by formal copy g)

(D) 20

Correct Answer: (C)

[EN] Formal parameter g hides global g inside fn(), so g = 20 modifies only the local parameter copy.

[HI] फॉर्मल पैरामीटर g फंक्शन के भीतर ग्लोबल g को ढक (Shadow) लेता है, अतः केवल स्थानीय कॉपी बदलती है और ग्लोबल g 5 रहता है।

Q15. Which statement is NOT true about Call by Value in C?

(C में कॉल बाई वैल्यू के बारे में इनमें से कौन सा कथन सत्य नहीं है?)

(A) Modifications made to formal parameters inside the callee automatically update the caller's actual variables

(B) Formal copies are discarded when the function returns

(C) Formal parameters occupy separate memory from caller variables

(D) Actual arguments may be constants or expressions

Correct Answer: (A)

[EN] In Call by Value, modifications stay strictly local to the callee's copies and never propagate back automatically.

[HI] कॉल बाई वैल्यू में फॉर्मल पैरामीटर्स पर किए गए बदलाव कॉलर के मूल वेरिएबल्स को स्वतः अपडेट नहीं करते।

Q16. What happens to the memory holding formal parameter copies once a function invoked via Call by Value executes return?

(कॉल बाई वैल्यू द्वारा बुलाए गए फंक्शन में return चलते ही फॉर्मल पैरामीटर्स की कॉपी वाली मेमोरी का क्या होता है?)

(A) It persists until program termination

(B) Caller must call free() manually

(C) It moves into the heap segment

(D) Its stack frame memory is popped and automatically reclaimed

Correct Answer: (D)

[EN] Stack-allocated formal parameters have automatic lifetime ending as soon as the function returns.

[HI] फंक्शन से return होते ही उसका स्टैक फ्रेम पॉप होकर वह मेमोरी स्वतः मुक्त हो जाती है।

Q17. Within Parameter Passing: Call by Value (Copying Values), which call by value property directly maps to: "Copies actual argument value into parameter"?

(Parameter Passing: Call by Value (Copying Values) में कौन सा Call by Value Property सीधे "Copies actual argument value into parameter" से संबंधित है?)

(A) Large Struct Impact

(B) Argument Flexibility

(C) Transfer Mechanism

(D) Memory Addresses

Correct Answer: (C)

[EN] In Parameter Passing: Call by Value (Copying Values), 'Transfer Mechanism' handles 'Copies actual argument value into parameter' (Original caller variables never change directly).

[HI] Parameter Passing: Call by Value (Copying Values) में 'Transfer Mechanism' का कार्य/विवरण 'Copies actual argument value into parameter' (Original caller variables never change directly) है।

Q18. Which option accurately describes 'Memory Addresses' in Parameter Passing: Call by Value (Copying Values)?

(Parameter Passing: Call by Value (Copying Values) के संदर्भ में 'Memory Addresses' की सही विशेषता कौन सी है?)

(A) Caller and callee hold separate stack addresses

(B) Copies actual argument value into parameter

(C) Copies entire byte footprint onto call stack

(D) Accepts literals, variables, and expressions

Correct Answer: (A)

[EN] 'Memory Addresses' provides 'Caller and callee hold separate stack addresses' — key point: Prevents accidental side effects across functions.

[HI] 'Memory Addresses' का मुख्य विवरण 'Caller and callee hold separate stack addresses' है (Prevents accidental side effects across functions)।

Q19. In Parameter Passing: Call by Value (Copying Values), identify the correct parameter for the specification: "Accepts literals, variables, and expressions".

(Parameter Passing: Call by Value (Copying Values) में "Accepts literals, variables, and expressions" विवरण किस विकल्प के लिए सही है?)

(A) Large Struct Impact

(B) Transfer Mechanism

(C) Argument Flexibility

(D) Memory Addresses

Correct Answer: (C)

[EN] 'Argument Flexibility' corresponds to 'Accepts literals, variables, and expressions' (No addressable memory lvalue needed at call).

[HI] 'Argument Flexibility' का संबंध 'Accepts literals, variables, and expressions' (No addressable memory lvalue needed at call) से है।

Q20. Considering Parameter Passing: Call by Value (Copying Values), what key behavior defines 'Large Struct Impact'?

(Parameter Passing: Call by Value (Copying Values) में 'Large Struct Impact' की मुख्य भूमिका या मान क्या है?)

(A) Copies entire byte footprint onto call stack

(B) Caller and callee hold separate stack addresses

(C) Copies actual argument value into parameter

(D) Accepts literals, variables, and expressions

Correct Answer: (A)

[EN] 'Large Struct Impact' represents 'Copies entire byte footprint onto call stack' (Slow for big structs; prefer const pointer).

[HI] 'Large Struct Impact' का अर्थ/मान 'Copies entire byte footprint onto call stack' है (Slow for big structs; prefer const pointer)।

Parameter Passing: Call by Value (Copying Values) — Exam FAQs

Q1: Does C support Call by Reference natively, or only Call by Value?

क्या C में कॉल बाई रेफरेंस स्वाभाविक रूप से उपलब्ध है या केवल कॉल बाई वैल्यू?

[EN] ISO C natively supports only Call by Value. Call by Reference behavior is simulated manually by passing memory addresses (&var) by value into pointer parameters (*ptr).

[HI] मानक ISO C में अंतर्निहित रूप से केवल कॉल बाई वैल्यू ही होता है। कॉल बाई रेफरेंस को पते (&var) पॉइंटर पैरामीटर (*ptr) में पास करके अनुकरण (Simulate) किया जाता है।

Q2: Why does 'void swap(int a, int b)' fail to swap variables in C?

'void swap(int a, int b)' फंक्शन C में मूल वेरिएबल्स को स्वैप करने में विफल क्यों होता है?

[EN] Because a and b receive copies of the caller's integers at different stack addresses; swapping a and b changes only those temporary copies, leaving the caller's originals intact.

[HI] क्योंकि a और b में कॉलर के मानों की केवल प्रतियाँ आती हैं; उन्हें आपस में बदलने से केवल अस्थायी कॉपियाँ बदलती हैं और मूल मान अप्रभावित रहते हैं।

Q3: How can you avoid copying a large struct by value without letting the called function modify it?

किसी बड़े struct को बिना बाय वैल्यू कॉपी किए पास करना और साथ ही उसमें बदलाव रोकना कैसे संभव है?

[EN] Pass its address as a pointer-to-const, such as 'void display(const struct Employee *e)', which copies only 4 or 8 bytes while letting the compiler block any writes to *e.

[HI] उसका पता पॉइंटर-टू-कॉन्स्ट ('const struct Employee *e') के रूप में पास करें; इससे केवल पते के 4 या 8 बाइट पास होते हैं और कंपाइलर डेटा में कोई बदलाव नहीं होने देता।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)