PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Increment and Decrement Operators: ++a vs a++ Pre/Post (इंक्रीमेंट/डिक्रीमेंट ऑपरेटर्स: प्री-इंक्रीमेंट (++a) बनाम पोस्ट-इंक्रीमेंट (a++)) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Increment (++) and decrement (--) operators modify a modifiable lvalue by 1, differing in whether they return the updated value (prefix ++a) or the prior value (postfix a++). Understanding sequence-point Undefined Behavior, pointer increments, and C vs C++ lvalue rules is critical in C exams.
अध्याय सार: इंक्रीमेंट (++) और डिक्रीमेंट (--) ऑपरेटर्स मॉडिफाएबल एल-वैल्यू के मान को 1 से बदलते हैं, जहाँ प्रीफिक्स (++a) नया मान तथा पोस्टफिक्स (a++) पुराना मान लौटाता है। सीक्वेंस पॉइंट के बिना दोहरे बदलाव से होने वाले Undefined Behavior, पॉइंटर इंक्रीमेंट और C बनाम C++ एल-वैल्यू नियम परीक्षा के लिए अति महत्वपूर्ण हैं।
Increment and Decrement Operators: ++a vs a++ Pre/Post: Detailed Notes & Architecture (इंक्रीमेंट/डिक्रीमेंट ऑपरेटर्स: प्री-इंक्रीमेंट (++a) बनाम पोस्ट-इंक्रीमेंट (a++))
1. Prefix (++a) vs Postfix (a++) Mechanics & Return Values (प्रीफिक्स (++a) बनाम पोस्टफिक्स (a++) की कार्यप्रणाली)
[EN] Prefix increment (`++a`) increments the operand `a` by 1 first and evaluates to the newly incremented value. Postfix increment (`a++`) captures the current value of `a` to return as the expression result, then schedules `a` to be incremented by 1 before the next sequence point (similarly for `--a` and `a--`). Neither operator can be applied to constants or temporary rvalues such as `5++` or `++(a + b)`, because both require a modifiable lvalue. Standalone statements like `i++;` and `++i;` yield identical final effects on `i`, though postfix `a++` and `a--` have higher operator precedence (tier 1) than prefix `++a` and `--a` (tier 2).
[HI] प्रीफिक्स इंक्रीमेंट (`++a`) पहले वेरिएबल `a` का मान 1 बढ़ाता है और फिर नया बढ़ा हुआ मान लौटाता है। इसके विपरीत, पोस्टफिक्स इंक्रीमेंट (`a++`) पहले `a` का पुराना मान एक्सप्रेशन को देता है और अगले सीक्वेंस पॉइंट से पहले `a` में 1 जोड़ देता है (यही नियम `--a` व `a--` पर लागू होता है)। चूंकि ये दोनों ऑपरेटर्स मेमोरी में मान बदलते हैं, इसलिए `5++` या `++(a + b)` जैसे नॉन-एल-वैल्यू पर इन्हें लगाना कंपाइल एरर देता है। पोस्टफिक्स `++`/`--` की प्राथमिकता प्रीफिक्स `++`/`--` से अधिक होती है।
2. Sequence Points & Undefined Behavior Trap (सीक्वेंस पॉइंट और अनडिफाइंड बिहेवियर का खतरा)
[EN] In ISO C, modifying a scalar variable more than once—or modifying it and reading it separately (outside calculating the new value)—without an intervening sequence point invokes Undefined Behavior (UB). Classic exam UB traps include `printf("%d %d", i++, ++i);`, `x = i++ + i++;`, and `i = i++;`. Because C leaves the evaluation order of function arguments and `+` operands unspecified, compilers can compute them in any order and optimize arbitrarily. By contrast, `a++ && ++a` IS completely well-defined because `&&` creates a mandatory sequence point after its left operand.
[HI] ISO C मानक में बिना किसी सीक्वेंस पॉइंट के एक ही वेरिएबल को एक से अधिक बार बदलना—या बदलने के साथ-साथ अलग से पढ़ना—Undefined Behavior (UB) उत्पन्न करता है। इसके प्रसिद्ध उदाहरण हैं: `printf("%d %d", i++, ++i);`, `x = i++ + i++;`, तथा `i = i++;`। C में फंक्शन आर्ग्युमेंट्स या `+` के दोनों पक्षों के चलने का क्रम तय नहीं होता, अतः इन एक्सप्रेशन का कोई एक निश्चित आउटपुट नहीं होता। हालांकि `a++ && ++a` पूरी तरह वैध है क्योंकि `&&` बीच में सीक्वेंस पॉइंट बनाता है।
3. Pointer Increment Arithmetic & Dereference Precedence (पॉइंटर इंक्रीमेंट अंकगणित और डीरेफरेंस प्राथमिकता)
[EN] When `++` or `--` is applied to a pointer `p` of type `T *`, incrementing `p` advances its memory address by `sizeof(T)` bytes—not 1 byte—so it moves cleanly to the next array element. Precedence rules strongly govern combined pointer expressions: postfix `++` binds tighter than unary `*`, so `*p++` parses as `*(p++)` (reads the current element `*p`, then advances pointer `p`). Conversely, `(*p)++` uses parentheses to fetch and increment the pointed integer value itself while keeping `p` at the same address, and `*++p` advances `p` first and dereferences the next element.
[HI] किसी `T *` पॉइंटर पर `++` लगाने पर वह मेमोरी में 1 बाइट नहीं, बल्कि `sizeof(T)` बाइट्स (अर्थात अगले तत्व पर) आगे बढ़ता है। पॉइंटर के साथ प्राथमिकता बहुत मायने रखती है: चूंकि पोस्टफिक्स `++` की प्राथमिकता यूनरी `*` से अधिक होती है, इसलिए `*p++` को `*(p++)` पढ़ा जाता है—यह वर्तमान स्थान का मान पढ़कर पॉइंटर `p` को आगे बढ़ाता है। इसके विपरीत `(*p)++` उसी पते पर रखे मान को 1 बढ़ाता है, और `*++p` पहले पॉइंटर को आगे बढ़ाकर नया मान पढ़ता है।
4. C vs C++ Lvalue Rule, sizeof Non-Evaluation & Maximal Munch (C बनाम C++ एल-वैल्यू नियम, sizeof व मैक्सिमल मंच नियम)
[EN] A subtle distinction between C and C++ appears with prefix increment: in C, `++a` yields an rvalue (not an lvalue), so `++a = 10;` fails to compile in C, whereas in C++ prefix `++a` returns an lvalue reference and compiles! Next, remember that `sizeof(a++)` inspects the static type of `a` at compile time without evaluating `a++`, leaving `a` completely unchanged. Finally, the C lexer follows the Maximal Munch rule (greedy tokenization): writing `a+++b` without spaces is tokenized left-to-right as `(a++) + b`, whereas `a+++++b` fails because `(a++)++` tries to increment an rvalue.
[HI] C और C++ के बीच एक सूक्ष्म अंतर यह है कि C में `++a` एक rvalue देता है (अतः `++a = 10;` C में अवैध है), जबकि C++ में प्रीफिक्स `++a` एक lvalue लौटाता है। दूसरा महत्वपूर्ण बिंदु यह है कि `sizeof(a++)` कंपाइल-टाइम पर टाइप जांचता है और `a++` को निष्पादित नहीं करता, जिससे `a` का मान अपरिवर्तित रहता है। लेक्सर के मैक्सिमल मंच (Maximal Munch) नियम के अनुसार बिना स्पेस वाला `a+++b` कोड `(a++) + b` के रूप में पढ़ा जाता है।
Syntax, Formula & Technical Example (Increment and Decrement Operators: ++a vs a++ Pre/Post)
#include <stdio.h>
int main() {
int a = 5, arr[] = {10, 20, 30}, *p = arr;
int x = a++;
int y = ++a;
int v1 = *p++;
printf("x=%d y=%d v1=%d v2=%d\n", x, y, v1, *p);
return 0;
}
// Output: x=5 y=7 v1=10 v2=20
Increment and Decrement Operators: ++a vs a++ Pre/Post Quick Reference & Comparison Table
| Expression Pattern | Execution & Value Rule | C Standard Exam Fact |
|---|---|---|
| Prefix Increment (++a) | Increments variable first then yields updated value | Returns rvalue in C (unlike lvalue in C++) |
| Postfix Increment (a++) | Yields original value first then schedules +1 update | Higher precedence than unary prefix operators |
| Pointer Post-Inc (*p++) | Dereferences current address then advances p by sizeof(*p) | Equivalent to *(p++) due to postfix precedence |
| Unsequenced (i++ + ++i) | Modifies scalar i multiple times without sequence point | Produces Undefined Behavior across C compilers |
Increment and Decrement Operators: ++a vs a++ Pre/Post Top 20 Bilingual MCQs with Answers
Q1. What is the output of `int a = 5, b, c; b = a++; c = ++a; printf("%d %d %d", a, b, c);`?
(`int a = 5, b, c; b = a++; c = ++a; printf("%d %d %d", a, b, c);` का आउटपुट क्या होगा?)
(A) 7 5 7
(B) 6 5 6
(C) 7 5 6
(D) 7 6 7
Correct Answer: (A)
[EN] a++ assigns original 5 to b and increments a to 6; ++a increments a to 7 and assigns 7 to c.
[HI] a++ पहले पुराना मान 5 b को देकर a को 6 बनाता है; फिर ++a से a 7 होकर c में 7 स्टोर होता है।
Q2. In `int arr[] = {10, 20, 30}; int *p = arr; int x = *p++;`, what are `x` and `*p` afterward?
(`int arr[] = {10, 20, 30}; int *p = arr; int x = *p++;` के बाद `x` और `*p` के मान क्या होंगे?)
(A) x = 10 and *p = 11
(B) x = 10 and *p = 20
(C) x = 11 and *p = 11
(D) x = 20 and *p = 20
Correct Answer: (B)
[EN] Postfix ++ binds tighter than *, parsing as *(p++): x gets *arr (10) and p advances to arr + 1 (pointing to 20).
[HI] पोस्टफिक्स ++ की प्राथमिकता * से अधिक है, अतः *(p++) चलता है: x को 10 मिलता है और पॉइंटर p अगले तत्व 20 पर पहुंच जाता है।
Q3. Which expression increments the value stored AT address `p` rather than advancing pointer `p`?
(पॉइंटर `p` को आगे बढ़ाए बिना `p` पर स्थित मान को 1 बढ़ाने के लिए कौन सा कोड सही है?)
(A) p++
(B) *(p++)
(C) *p++
(D) (*p)++
Correct Answer: (D)
[EN] Parentheses force *p to dereference first, and postfix ++ increments the dereferenced target variable.
[HI] कोष्ठक पहले *p को डीरेफरेंस करते हैं और फिर पोस्टफिक्स ++ उस मेमोरी स्थान पर रखे मान को 1 बढ़ाता है।
Q4. What does `int i = 5; printf("%d", sizeof(i++)); printf(" %d", i);` output (assuming 4-byte `int`)?
(4-बाइट `int` मानकर `int i = 5; printf("%d", sizeof(i++)); printf(" %d", i);` क्या प्रिंट करेगा?)
(A) Compile error
(B) 4 5
(C) 5 6
(D) 4 6
Correct Answer: (B)
[EN] sizeof determines the size of i's type (int = 4) at compile time without evaluating i++, so i remains 5.
[HI] sizeof कंपाइल-टाइम पर केवल टाइप का आकार (4 बाइट) देखता है और i++ को निष्पादित नहीं करता, इसलिए i = 5 ही रहता है।
Q5. How does the ISO C standard classify `int i = 1; printf("%d %d", i++, ++i);`?
(ISO C मानक `int i = 1; printf("%d %d", i++, ++i);` को किस रूप में वर्गीकृत करता है?)
(A) Mandatory compile-time syntax error
(B) Guaranteed output 1 3
(C) Undefined Behavior (unsequenced modification of i)
(D) Guaranteed output 2 3
Correct Answer: (C)
[EN] Function arguments are separated by commas that are NOT comma operators; there is no sequence point between arguments, making multiple updates to i UB.
[HI] फंक्शन आर्ग्युमेंट्स के बीच सीक्वेंस पॉइंट नहीं होता; एक ही वेरिएबल i को दो बार बदलने से यह Undefined Behavior बन जाता है।
Q6. What happens when compiling `int a = 10; ++a = 20;` in a C compiler vs a C++ compiler?
(`int a = 10; ++a = 20;` को C कंपाइलर बनाम C++ कंपाइलर में चलाने पर क्या होता है?)
(A) Valid in C, compile error in C++
(B) Valid in both C and C++
(C) Compile error in C (not an lvalue), valid in C++
(D) Compile error in both C and C++
Correct Answer: (C)
[EN] In C, prefix ++a returns an rvalue (assigning 20 fails), whereas C++ defines prefix ++a to return an lvalue reference.
[HI] C भाषा में प्रीफिक्स ++a एक rvalue लौटाता है जिस पर असाइनमेंट अवैध है, जबकि C++ में ++a एक lvalue रेफरेंस लौटाता है।
Q7. Using C's Maximal Munch tokenization rule, how does the compiler parse `z = x+++y;` when `x = 3, y = 4`?
(C के मैक्सिमल मंच नियम से `x = 3, y = 4` होने पर `z = x+++y;` किस प्रकार हल होगा?)
(A) Parses as z = x + (++y), giving z = 8 and y = 5
(B) Always fails with syntax error
(C) Parses as (x + + + y)
(D) Parses as z = (x++) + y, giving z = 7 and x = 4
Correct Answer: (D)
[EN] The lexer greedily reads `++` first, then `+`, forming `(x++) + y` = 3 + 4 = 7 while x becomes 4.
[HI] लेक्सर बाएँ से दाएँ अधिकतम मान्य टोकन `++` पहले बनाता है, जिससे `(x++) + y` = 3 + 4 = 7 प्राप्त होता है और x = 4 हो जाता है।
Q8. If `double *ptr = (double *)1000;` (where `sizeof(double) == 8`), what numeric address does `ptr` hold after `ptr++;`?
(यदि `double *ptr = (double *)1000;` (जहाँ `sizeof(double) == 8`) हो, तो `ptr++;` के बाद नया एड्रेस क्या होगा?)
(A) 1002
(B) 1001
(C) 1008
(D) 1004
Correct Answer: (C)
[EN] Incrementing a double* pointer advances it by 1 * sizeof(double) = 8 bytes, moving from 1000 to 1008.
[HI] double* पॉइंटर को ++ करने पर वह 1 * sizeof(double) अर्थात 8 बाइट्स आगे बढ़कर 1008 पर पहुंच जाता है।
Q9. What is the output of `int a = 2, b = 3; int r = a++ + ++b; printf("%d %d %d", r, a, b);`?
(`int a = 2, b = 3; int r = a++ + ++b; printf("%d %d %d", r, a, b);` का आउटपुट क्या होगा?)
(A) 5 3 4
(B) 6 3 4
(C) 7 3 4
(D) Undefined Behavior
Correct Answer: (B)
[EN] a and b are distinct variables, so this is completely well-defined: a++ contributes 2 (a becomes 3), ++b contributes 4 (b becomes 4), sum = 6.
[HI] a और b दो अलग-अलग वेरिएबल हैं अतः यह पूरी तरह वैध है: a++ से 2 और ++b से 4 जुड़कर r = 6 बनता है और a=3, b=4 होते हैं।
Q10. Why does `int x = (5)++;` fail to compile in C?
(C में `int x = (5)++;` कंपाइल होने में विफल क्यों होता है?)
(A) 5++ returns a float
(B) Postfix ++ works only on variables named i or j
(C) Literal 5 is a constant rvalue, whereas ++ requires a modifiable lvalue
(D) Parentheses cannot surround an operand of ++
Correct Answer: (C)
[EN] Increment and decrement operators write back to memory and thus require a modifiable lvalue.
[HI] ++ और -- ऑपरेटर्स को मान सहेजने के लिए एक मॉडिफाएबल एल-वैल्यू (मेमोरी स्थान) चाहिए, जो स्थिरांक 5 के पास नहीं होता।
Q11. What is printed by `int x = 10; while (x-- > 8) printf("%d ", x);`?
(`int x = 10; while (x-- > 8) printf("%d ", x);` क्या प्रिंट करेगा?)
(A) 10 9
(B) 9 8 7
(C) 10 9 8
(D) 9 8
Correct Answer: (D)
[EN] Test 1: x-- yields 10 > 8 (true), x becomes 9, prints 9. Test 2: x-- yields 9 > 8 (true), x becomes 8, prints 8. Test 3: 8 > 8 (false), loop stops.
[HI] पहले चक्र में 10 > 8 सत्य होकर x=9 प्रिंट होता है; दूसरे में 9 > 8 सत्य होकर x=8 प्रिंट होता है; तीसरे में 8 > 8 असत्य होकर लूप रुकता है।
Q12. What is printed by `int x = 10; while (--x > 8) printf("%d ", x);`?
(`int x = 10; while (--x > 8) printf("%d ", x);` क्या प्रिंट करेगा?)
(A) 8
(B) 9
(C) 10 9
(D) 9 8
Correct Answer: (B)
[EN] Test 1: --x turns 10 into 9, 9 > 8 is true, prints 9. Test 2: --x turns 9 into 8, 8 > 8 is false, loop ends.
[HI] पहले चक्र में --x से x=9 होकर 9 > 8 सत्य होता है (9 प्रिंट); दूसरे चक्र में x=8 होकर 8 > 8 असत्य हो जाता है और लूप रुक जाता है।
Q13. Which expression evaluates cleanly without Undefined Behavior in ISO C?
(ISO C में इनमें से कौन सा एक्सप्रेशन बिना किसी Undefined Behavior के पूरी तरह वैध है?)
(A) arr[a] = a++
(B) a++ + ++a
(C) a++ && ++a
(D) a = a++
Correct Answer: (C)
[EN] The && operator introduces a sequence point after its left operand, sequencing the first increment completely before ++a executes.
[HI] && अपने बाएँ ऑपरेंड के बाद सीक्वेंस पॉइंट बनाता है, जिससे a++ और ++a के बीच स्पष्ट क्रम बना रहता है (अन्य विकल्पों में UB है)।
Q14. What is the result of `int a = 4; int b = a-- - --a;` in ISO C?
(ISO C में `int a = 4; int b = a-- - --a;` का क्या परिणाम होता है?)
(A) 0
(B) Undefined Behavior
(C) 1
(D) 2
Correct Answer: (B)
[EN] a is modified twice (a-- and --a) within the same expression without an intervening sequence point.
[HI] एक ही एक्सप्रेशन में बिना सीक्वेंस पॉइंट के वेरिएबल a को दो बार बदला गया है, अतः यह Undefined Behavior है।
Q15. Which statement is NOT true about increment and decrement operators in C?
(C में इंक्रीमेंट व डिक्रीमेंट ऑपरेटर्स के बारे में कौन सा कथन असत्य है?)
(A) Postfix ++ has higher precedence than unary dereference *
(B) Both ++ and -- require a modifiable lvalue operand
(C) Prefix ++a and postfix a++ share identical precedence in the C operator table
(D) Applying ++ to a float variable increments it by 1.0
Correct Answer: (C)
[EN] Postfix ++/-- sit at precedence tier 1 (left-to-right), whereas prefix ++/-- sit at tier 2 (right-to-left).
[HI] पोस्टफिक्स ++/-- की प्राथमिकता (स्तर 1) प्रीफिक्स ++/-- (स्तर 2) से अधिक होती है, दोनों की प्राथमिकता समान नहीं होती।
Q16. Can `++` and `--` be applied to floating-point variables like `double d = 2.5; d++;` in C?
(क्या C में `double d = 2.5; d++;` जैसे फ्लोटिंग-पॉइंट वेरिएबल पर `++` लगाया जा सकता है?)
(A) No, compile error because ++ works strictly on integers
(B) Yes, but it increments only the mantissa bit by 1
(C) Yes, d becomes 3.5
(D) Only in C++ and not in C
Correct Answer: (C)
[EN] ISO C allows ++ and -- on real floating-point types as well as integers and pointers, adding/subtracting 1.0.
[HI] ISO C में पूर्णांक और पॉइंटर के साथ-साथ float/double वेरिएबल पर भी ++/-- (जो 1.0 जोड़ता/घटाता है) पूर्णतः वैध है।
Q17. Within Increment and Decrement Operators: ++a vs a++ Pre/Post, which expression pattern directly maps to: "Increments variable first then yields updated value"?
(Increment and Decrement Operators: ++a vs a++ Pre/Post में कौन सा Expression Pattern सीधे "Increments variable first then yields updated value" से संबंधित है?)
(A) Postfix Increment (a++)
(B) Pointer Post-Inc (*p++)
(C) Prefix Increment (++a)
(D) Unsequenced (i++ + ++i)
Correct Answer: (C)
[EN] In Increment and Decrement Operators: ++a vs a++ Pre/Post, 'Prefix Increment (++a)' handles 'Increments variable first then yields updated value' (Returns rvalue in C (unlike lvalue in C++)).
[HI] Increment and Decrement Operators: ++a vs a++ Pre/Post में 'Prefix Increment (++a)' का कार्य/विवरण 'Increments variable first then yields updated value' (Returns rvalue in C (unlike lvalue in C++)) है।
Q18. Which option accurately describes 'Postfix Increment (a++)' in Increment and Decrement Operators: ++a vs a++ Pre/Post?
(Increment and Decrement Operators: ++a vs a++ Pre/Post के संदर्भ में 'Postfix Increment (a++)' की सही विशेषता कौन सी है?)
(A) Increments variable first then yields updated value
(B) Dereferences current address then advances p by sizeof(*p)
(C) Modifies scalar i multiple times without sequence point
(D) Yields original value first then schedules +1 update
Correct Answer: (D)
[EN] 'Postfix Increment (a++)' provides 'Yields original value first then schedules +1 update' — key point: Higher precedence than unary prefix operators.
[HI] 'Postfix Increment (a++)' का मुख्य विवरण 'Yields original value first then schedules +1 update' है (Higher precedence than unary prefix operators)।
Q19. In Increment and Decrement Operators: ++a vs a++ Pre/Post, identify the correct parameter for the specification: "Dereferences current address then advances p by sizeof(*p)".
(Increment and Decrement Operators: ++a vs a++ Pre/Post में "Dereferences current address then advances p by sizeof(*p)" विवरण किस विकल्प के लिए सही है?)
(A) Pointer Post-Inc (*p++)
(B) Unsequenced (i++ + ++i)
(C) Postfix Increment (a++)
(D) Prefix Increment (++a)
Correct Answer: (A)
[EN] 'Pointer Post-Inc (*p++)' corresponds to 'Dereferences current address then advances p by sizeof(*p)' (Equivalent to *(p++) due to postfix precedence).
[HI] 'Pointer Post-Inc (*p++)' का संबंध 'Dereferences current address then advances p by sizeof(*p)' (Equivalent to *(p++) due to postfix precedence) से है।
Q20. Considering Increment and Decrement Operators: ++a vs a++ Pre/Post, what key behavior defines 'Unsequenced (i++ + ++i)'?
(Increment and Decrement Operators: ++a vs a++ Pre/Post में 'Unsequenced (i++ + ++i)' की मुख्य भूमिका या मान क्या है?)
(A) Dereferences current address then advances p by sizeof(*p)
(B) Yields original value first then schedules +1 update
(C) Increments variable first then yields updated value
(D) Modifies scalar i multiple times without sequence point
Correct Answer: (D)
[EN] 'Unsequenced (i++ + ++i)' represents 'Modifies scalar i multiple times without sequence point' (Produces Undefined Behavior across C compilers).
[HI] 'Unsequenced (i++ + ++i)' का अर्थ/मान 'Modifies scalar i multiple times without sequence point' है (Produces Undefined Behavior across C compilers)।
Increment and Decrement Operators: ++a vs a++ Pre/Post — Exam FAQs
Q1: Why does `printf("%d %d", i++, ++i)` produce unpredictable results in C?
C में `printf("%d %d", i++, ++i)` का आउटपुट अनिश्चित या अमान्य क्यों होता है?
[EN] C does not specify the order in which function arguments are evaluated, and commas separating function arguments are NOT sequence points. Modifying `i` twice without a sequence point triggers Undefined Behavior, meaning different compilers or optimization flags yield completely different outputs.
[HI] C में फंक्शन आर्ग्युमेंट्स के मूल्यांकन का क्रम तय नहीं है और उनके बीच के कॉमा सीक्वेंस पॉइंट नहीं बनाते। एक ही वेरिएबल को दो बार बदलने से Undefined Behavior होता है जिससे अलग-अलग कंपाइलर अलग उत्तर दे सकते हैं।
Q2: What is the difference between `*p++`, `(*p)++`, and `*++p`?
`*p++`, `(*p)++`, और `*++p` में क्या अंतर है?
[EN] `*p++` dereferences the current pointer then advances `p` to the next element; `(*p)++` increments the value stored at `*p` while leaving `p` unchanged; `*++p` advances `p` first and then dereferences the newly pointed element.
[HI] `*p++` वर्तमान मान पढ़कर पॉइंटर `p` को आगे बढ़ाता है; `(*p)++` उस पते पर रखे मान को 1 बढ़ाता है (पॉइंटर वहीं रहता है); `*++p` पहले पॉइंटर को आगे बढ़ाता है और फिर नए स्थान का मान पढ़ता है।
Q3: Why doesn't `sizeof(x++)` increment `x`?
`sizeof(x++)` लिखने पर `x` का मान क्यों नहीं बढ़ता?
[EN] `sizeof` is evaluated at compile time using only the static type of its operand (`x++` has type `int`), so the runtime expression inside `sizeof` is never executed (except for C99 variable-length arrays).
[HI] `sizeof` कंपाइल-टाइम पर केवल एक्सप्रेशन के डेटा टाइप का आकार जांचता है और उसके अंदर के कोड (जैसे `x++`) को रनटाइम पर निष्पादित नहीं करता।
Post a Comment
Post a Comment