Decision Making: Simple if, if-else, Nested if-else Notes in Hindi & English : कंडीशनल स्टेटमेंट्स: if, if-else और नेस्टेड if-else की संरचना और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Decision Making: Simple if, if-else, Nested if-else (कंडीशनल स्टेटमेंट्स: if, if-else और नेस्टेड if-else की संरचना) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Decision-making statements in C (simple if, if-else, else-if ladder, and nested if-else) control conditional execution using scalar truthiness where 0 is false and any non-zero value is true. Avoiding dangling-else mismatches, stray semicolons, and unbraced multi-statement bugs ensures reliable branching.

अध्याय सार: C में डिसीजन-मेकिंग स्टेटमेंट्स (simple if, if-else, else-if ladder, तथा nested if-else) स्केलर शर्तों (0 असत्य, कोई भी गैर-शून्य मान सत्य) के आधार पर प्रोग्राम प्रवाह नियंत्रित करते हैं। डैंगलिंग-एल्स (Dangling else) नियम, अनावश्यक सेमीकोलन व बिना ब्रैकेट `{}` के बग्स से बचना सुरक्षित कोडिंग की कुंजी है।

Decision Making: Simple if, if-else, Nested if-else: Detailed Notes & Architecture (कंडीशनल स्टेटमेंट्स: if, if-else और नेस्टेड if-else की संरचना)

1. Simple if Statement, Truthiness & Null-Statement Semicolon Bug (सिंपल if स्टेटमेंट, सत्यता नियम और सेमीकोलन बग)

[EN] A simple `if (condition) statement;` evaluates any scalar `condition` expression (int, float, or pointer). If non-zero, it executes the controlled statement (single statement or compound `{ ... }` block); if zero (0, 0.0, `-0.0`, or `NULL`), control jumps past it. Two classic C traps appear here: first, placing a trailing semicolon `if (x > 10); printf("Hi");` turns `;` into the empty null body of `if`, causing `printf("Hi")` to run unconditionally! Second, in ISO C99/C11/C17, writing a declaration directly inside an unbraced branch (`if (cond) int y = 5;`) is a syntax error—compound braces `{ int y = 5; }` are mandatory.

[HI] साधारण `if (condition)` किसी भी स्केलर शर्त को जांचता है: गैर-शून्य मान होने पर उसके अधीन स्टेटमेंट या `{ ... }` ब्लॉक चलता है, और 0 (या `NULL`) होने पर वह छूट जाता है। इसमें दो प्रमुख त्रुटियाँ होती हैं: पहला, `if (x > 10); printf("Hi");` में सेमीकोलन `;` खाली स्टेटमेंट बनकर `if` को वहीं खत्म कर देता है जिससे `printf` हमेशा चलता है। दूसरा, बिना ब्रैकेट `{}` के `if (cond) int y = 5;` लिखना C में सिंटैक्स एरर है क्योंकि डिक्लेरेशन को ब्लॉक ब्रैकेट की आवश्यकता होती है।

2. Two-Way if-else & Sequential else-if Ladder (द्वि-मार्गी if-else और else-if सीढ़ी)

[EN] `if (cond) stmt1; else stmt2;` guarantees mutually exclusive execution of exactly one branch. Note that `else` NEVER accepts a standalone condition—writing `else (x < 0)` without `if` is a compile error, and an `else` with no matching preceding `if` (e.g., broken by `if(cond);`) fails compilation. For multi-way branching, the `else if` ladder tests conditions top-down and exits as soon as the FIRST true condition matches, skipping all lower checks. Always order narrower/higher-priority tests first so broader conditions do not shadow later branches.

[HI] `if-else` दो परस्पर अनन्य शाखाओं में से ठीक एक को चलाता है। ध्यान दें कि अकेला `else` कभी कंडीशन नहीं लेता—`else (x < 0)` लिखने पर सिंटैक्स एरर आता है, तथा बिना पूर्ववर्ती `if` के `else` अवैध होता है। बहु-शाखा निर्णय के लिए `else if` सीढ़ी ऊपर से नीचे क्रमशः शर्तें जांचती है और पहली सत्य शर्त मिलते ही शेष सभी जांचों को छोड़कर बाहर आ जाती है। इसलिए अधिक विशिष्ट शर्तों को हमेशा ऊपर रखना चाहिए।

3. Nested if-else & The Dangling Else Rule (नेस्टेड if-else और डैंगलिंग एल्स (Dangling Else) नियम)

[EN] Nesting places an `if` or `if-else` inside another `if` or `else` block to model dependent multi-factor decisions (such as leap-year or permission checks). When braces `{}` are omitted in nested statements like `if (a) if (b) s1; else s2;`, visual indentation can deceive programmers into thinking `else` pairs with the outer `if (a)`. However, ISO C grammar strictly enforces the Dangling Else Rule: every `else` ALWAYS binds to the NEAREST preceding unmatched `if`. Thus in the snippet above, `else s2;` belongs strictly to the inner `if (b)`—so if `a == 0`, nothing executes at all!

[HI] एक `if` या `else` के अंदर दूसरा `if-else` लिखना नेस्टेड कंडीशनल कहलाता है। जब नेस्टेड `if (a) if (b) s1; else s2;` में ब्रैकेट `{}` न लगाए जाएँ, तो 'डैंगलिंग एल्स' (Dangling Else) अस्पष्टता पैदा होती है। इंडेंटेशन कैसा भी हो, ISO C व्याकरण के अनुसार प्रत्येक `else` हमेशा अपने से ठीक पहले वाले निकटतम अन-मैच्ड `if` से ही जुड़ता है! अर्थात ऊपर दिए उदाहरण में `else s2;` आंतरिक `if (b)` का भाग है; यदि `a == 0` हुआ तो दोनों में से कुछ नहीं चलेगा।

4. Bracing Discipline, 'goto fail' Vulnerability & if-else vs switch (ब्रैकेट अनुशासन, सुरक्षा बग व switch से तुलना)

[EN] Omitting `{}` on single-line `if` statements leads to catastrophic maintenance and security bugs—famously exemplified by Apple's 2014 SSL `goto fail;` vulnerability, where a duplicate unbraced `goto fail;` line executed unconditionally and bypassed signature verification! Always wrap every `if` and `else` body in `{}`. Furthermore, choose an `else-if` ladder over `switch` whenever conditions involve relational ranges (`score >= 75`), floating-point comparisons, multiple variables (`a > b && c == 1`), or string comparisons via `strcmp()`, because `switch` accepts only integer constant labels.

[HI] एक-लाइन वाले `if` में `{}` न लगाना गंभीर सुरक्षा खतरे पैदा करता है—जिसका प्रसिद्ध उदाहरण 2014 का Apple `goto fail;` बग था, जहाँ ब्रैकेट न होने से दूसरी लाइन बिना शर्त चलकर SSL जांच को बायपास कर देती थी। अतः हर `if`/`else` ब्लॉक में `{}` लगाना सर्वोत्तम अभ्यास है। जब शर्तों में रेंज (`score >= 75`), दशमलव मान, एक से अधिक वेरिएबल या `strcmp()` स्ट्रिंग तुलना हो, तब `switch` (जो केवल पूर्णांक स्थिरांक लेता है) के बजाय `if-else if` का ही उपयोग होता है।

Syntax, Formula & Technical Example (Decision Making: Simple if, if-else, Nested if-else)

#include <stdio.h>
int main() {
    int a = 0, b = 1;
    if (a) if (b) printf("X"); else printf("Y"); // else binds to inner if(b)!
    int score = 82;
    if (score >= 90) printf("Grade A\n");
    else if (score >= 75) printf("Grade B\n");
    else printf("Grade C\n");
    return 0;
}
// Output: Grade B

Decision Making: Simple if, if-else, Nested if-else Quick Reference & Comparison Table

Decision ConstructExecution & Binding RuleCommon Exam Bug
Simple if StatementRuns body only when scalar condition evaluates non-zeroTrailing semicolon if(cond); creates empty body
Two-Way if-elseExecutes strictly one mutually exclusive branchPlacing condition directly after else causes compile error
else-if Multi-Way LadderTests conditions top-down stopping at first true matchBroader top check shadows narrower lower check
Dangling else RulePairs else strictly with nearest preceding unmatched ifVisual indentation misleads reader about compiler binding

Decision Making: Simple if, if-else, Nested if-else Top 20 Bilingual MCQs with Answers

Q1. How does C resolve the 'Dangling Else' problem when braces are omitted in `if (a) if (b) s1; else s2;`?

(जब `if (a) if (b) s1; else s2;` में ब्रैकेट `{}` न हों, तो C 'डैंगलिंग एल्स' समस्या को कैसे सुलझाता है?)

(A) Binding depends on source code indentation

(B) The else binds to the outermost `if (a)`

(C) Compiler throws an ambiguity syntax error

(D) The else always binds to the nearest preceding unmatched if (here, `if (b)`)

Correct Answer: (D)

[EN] ISO C specifies that an else clause always pairs with the innermost (nearest preceding) unmatched if, ignoring whitespace/indentation.

[HI] ISO C मानक के अनुसार `else` सदैव अपने ठीक पहले आने वाले निकटतम अन-मैच्ड `if` (`if (b)`) से जुड़ता है, न कि इंडेंटेशन के अनुसार।

Q2. What is the output of `int a = 0, b = 1; if (a) if (b) printf("Yes"); else printf("No");`?

(`int a = 0, b = 1; if (a) if (b) printf("Yes"); else printf("No");` का आउटपुट क्या होगा?)

(A) No

(B) Compile error

(C) Nothing is printed (blank output)

(D) Yes

Correct Answer: (C)

[EN] Because `else` pairs with inner `if (b)`, the entire `if (b) ... else ...` lives inside `if (a)`. Since a is 0, nothing executes.

[HI] `else` आंतरिक `if (b)` का भाग है, जो स्वयं बाहरी `if (a)` के अंदर है; `a = 0` होने से बाहरी `if` में प्रवेश ही नहीं होता और कुछ प्रिंट नहीं होता।

Q3. What does `int x = 5; if (x > 10); printf("Done");` print?

(`int x = 5; if (x > 10); printf("Done");` क्या प्रिंट करेगा?)

(A) Nothing is printed

(B) Compile error

(C) 5

(D) Done

Correct Answer: (D)

[EN] The semicolon immediately after `if (x > 10)` serves as an empty null statement; `printf("Done")` is outside the `if` and always executes.

[HI] `if (x > 10)` के ठीक बाद लगा `;` एक खाली स्टेटमेंट बन जाता है; `printf("Done")` उसके बाहर होने से सदैव चलता है।

Q4. What happens when compiling `int x = 5; if (x > 10); printf("A"); else printf("B");`?

(`int x = 5; if (x > 10); printf("A"); else printf("B");` को कंपाइल करने पर क्या होगा?)

(A) Prints B

(B) Compile error: 'else' without a previous 'if'

(C) Prints AB

(D) Prints A

Correct Answer: (B)

[EN] The semicolon ended the `if` statement, leaving `printf("A");` between `if` and `else`, so `else` becomes orphaned.

[HI] सेमीकोलन `;` से `if` वहीं समाप्त हो गया, जिससे बीच में `printf("A")` आने पर `else` को कोई संगत `if` नहीं मिलता और कंपाइल एरर आता है।

Q5. What happens when compiling `if (1) int val = 10;` (without curly braces `{}`) in ISO C99/C11?

(ISO C99/C11 में बिना `{}` ब्रैकेट के `if (1) int val = 10;` को कंपाइल करने पर क्या होता है?)

(A) Compiles cleanly and val equals 10

(B) val becomes global automatically

(C) Prints warning only and runs

(D) Syntax/compile error because a variable declaration cannot be the sole substatement of if

Correct Answer: (D)

[EN] In C syntax, `if (expr) statement` requires a statement, whereas a declaration requires enclosing `{ }` compound block.

[HI] C के व्याकरण में `if` के बाद स्टेटमेंट चाहिए होता है, डिक्लेरेशन नहीं; बिना `{ }` के अंदर वेरिएबल घोषित करने पर कंपाइल त्रुटि आती है।

Q6. What does `if (-0.0) printf("True"); else printf("False");` print in C?

(C में `if (-0.0) printf("True"); else printf("False");` क्या प्रिंट करेगा?)

(A) Undefined Behavior

(B) False

(C) True

(D) Compile error

Correct Answer: (B)

[EN] Negative zero (-0.0) compares equal to zero numerically in IEEE 754, so it evaluates as false.

[HI] IEEE 754 में `-0.0` का संख्यात्मक मान 0 के बराबर होता है, इसलिए `if` शर्त असत्य होकर `False` प्रिंट होता है।

Q7. What does `if (-42) printf("Run"); else printf("Skip");` print in C?

(C में `if (-42) printf("Run"); else printf("Skip");` क्या प्रिंट करेगा?)

(A) Skip

(B) Nothing

(C) Run

(D) Compile error

Correct Answer: (C)

[EN] In C, zero is false and EVERY non-zero value—positive or negative—is considered true.

[HI] C भाषा में 0 को असत्य और धनात्मक या ऋणात्मक किसी भी गैर-शून्य संख्या (-42) को सत्य माना जाता है।

Q8. In an `else-if` ladder (`if (c1) A; else if (c2) B; else C;`), suppose both `c1` and `c2` are true. What executes?

(यदि किसी `else-if` सीढ़ी (`if (c1) A; else if (c2) B; else C;`) में `c1` और `c2` दोनों सत्य हों, तो क्या चलेगा?)

(A) Both A and B execute

(B) Only A executes; B and C are skipped

(C) Only B executes

(D) A, B, and C all execute

Correct Answer: (B)

[EN] An else-if ladder stops immediately after executing the first matching true branch.

[HI] `else-if` सीढ़ी पहली सत्य शर्त (`c1`) मिलते ही `A` चलाकर बाकी पूरी सीढ़ी से बाहर निकल जाती है।

Q9. Identify the syntax bug in `if (a > b) printf("A"); else (a < b) printf("B");`:

(`if (a > b) printf("A"); else (a < b) printf("B");` में क्या सिंटैक्स त्रुटि है?)

(A) printf cannot follow else

(B) Parentheses cannot surround a < b

(C) `else` cannot directly take a condition without the `if` keyword (`else if` is needed)

(D) Semicolon after printf("A") is illegal

Correct Answer: (C)

[EN] `else` takes no condition; chaining another condition requires writing `else if (a < b)`.

[HI] `else` सीधे शर्त स्वीकार नहीं करता; अगली शर्त जांचने के लिए `else if (a < b)` लिखना अनिवार्य है।

Q10. Why did Apple's infamous 2014 'goto fail' security bug occur in C?

(C में 2014 का प्रसिद्ध Apple 'goto fail' सुरक्षा बग किस कोडिंग गलती के कारण हुआ था?)

(A) Integer overflow inside a switch statement

(B) Using == instead of = inside if()

(C) An unbraced `if` controlled only the first `goto fail;`, leaving the second `goto fail;` to run unconditionally

(D) A missing semicolon after if()

Correct Answer: (C)

[EN] Without `{}` braces, duplicating `goto fail;` on the next indented line bypassed the conditional check and jumped directly to error cleanup.

[HI] ब्रैकेट `{}` न होने के कारण इंडेंटेड दूसरी `goto fail;` लाइन `if` के नियंत्रण से बाहर रहकर बिना शर्त चल पड़ी और सुरक्षा जांच टूट गई।

Q11. When MUST you use an `if-else if` ladder rather than a `switch` statement in C?

(C में `switch` स्टेटमेंट के बजाय `if-else if` सीढ़ी का उपयोग कब अनिवार्य होता है?)

(A) When checking exact integer equality like choice == 1

(B) When performance of 50 constant cases matters

(C) When branching on floating-point values, relational ranges (x >= 50), or strcmp() strings

(D) When branching on single char constants like 'A'

Correct Answer: (C)

[EN] C's `switch` accepts only integral expressions and constant integer case labels; ranges, floats, and strings require `if-else if`.

[HI] `switch` केवल पूर्णांक और कॉन्स्टेंट केस लेबल लेता है; रेंज, फ्लोट मान या `strcmp()` स्ट्रिंग तुलना के लिए `if-else if` आवश्यक है।

Q12. Look at: `int marks = 92; if (marks >= 40) printf("Pass"); else if (marks >= 90) printf("Top");`. What prints?

(`int marks = 92; if (marks >= 40) printf("Pass"); else if (marks >= 90) printf("Top");` का आउटपुट क्या होगा?)

(A) Pass

(B) PassTop

(C) Top

(D) Compile error

Correct Answer: (A)

[EN] Because `marks >= 40` appears first and is true for 92, it matches immediately and shadows the `marks >= 90` branch.

[HI] `marks >= 40` की व्यापक शर्त पहले आने से 92 वहीं मैच होकर `Pass` प्रिंट करता है और `marks >= 90` तक नियंत्रण पहुंचता ही नहीं।

Q13. What is the scope of `temp` in `if (x > 0) { int temp = x * 2; } printf("%d", temp);`?

(`if (x > 0) { int temp = x * 2; } printf("%d", temp);` कोड का परिणाम क्या होगा?)

(A) Prints 2*x when x > 0

(B) Prints 0

(C) Prints garbage value when x <= 0

(D) Compile error: 'temp' undeclared outside the if block

Correct Answer: (D)

[EN] Variables declared inside `{ ... }` have block scope restricted strictly to that compound block.

[HI] `{ ... }` के अंदर घोषित `temp` का स्कोप उसी ब्लॉक तक सीमित रहता है; ब्लॉक के बाहर उसका उपयोग करने पर कंपाइल त्रुटि आती है।

Q14. Which condition correctly checks whether integer year `y` is a Gregorian leap year using nested/logical rules?

(ग्रेगोरियन लीप वर्ष `y` की जांच करने वाली सही कंडीशन कौन सी है?)

(A) y % 100 != 0 && y % 400 == 0

(B) y % 4 == 0 || y % 100 == 0

(C) y % 4 == 0 && y % 400 == 0

(D) (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)

Correct Answer: (D)

[EN] A year is leap if divisible by 400, OR divisible by 4 while not divisible by 100 (e.g., 1900 is NOT leap, 2000 IS leap).

[HI] वर्ष या तो 400 से विभाज्य हो, या फिर 4 से विभाज्य होते हुए 100 से विभाज्य न हो (जैसे 1900 लीप नहीं है, पर 2000 लीप है)।

Q15. Which statement is NOT true about `if` and `if-else` in C?

(C में `if` और `if-else` के बारे में इनमें से कौन सा कथन असत्य है?)

(A) Curly braces {} allow grouping multiple statements into one conditional branch

(B) Zero (0 or NULL) evaluates as false while non-zero values evaluate as true

(C) Visual indentation decides which `if` an `else` pairs with in nested conditionals

(D) Any scalar expression can be tested inside if(expr)

Correct Answer: (C)

[EN] C compilers ignore indentation whitespace completely; `else` always pairs with the nearest unmatched `if`.

[HI] C कंपाइलर इंडेंटेशन को अनदेखा करते हैं; `else` हमेशा निकटतम अन-मैच्ड `if` से ही जुड़ता है।

Q16. What is printed by `int x = 3; if (x == 5) printf("A"); printf("B");`?

(`int x = 3; if (x == 5) printf("A"); printf("B");` क्या प्रिंट करेगा?)

(A) B

(B) A

(C) AB

(D) Nothing

Correct Answer: (A)

[EN] Without braces, `if (x == 5)` controls only `printf("A")` (skipped since 3 != 5); `printf("B")` runs unconditionally.

[HI] ब्रैकेट न होने से `if (x == 5)` केवल `printf("A")` को नियंत्रित करता है (जो छूट जाता है), और `printf("B")` स्वतंत्र रूप से चलता है।

Q17. Within Decision Making: Simple if, if-else, Nested if-else, which decision construct directly maps to: "Runs body only when scalar condition evaluates non-zero"?

(Decision Making: Simple if, if-else, Nested if-else में कौन सा Decision Construct सीधे "Runs body only when scalar condition evaluates non-zero" से संबंधित है?)

(A) Two-Way if-else

(B) Simple if Statement

(C) else-if Multi-Way Ladder

(D) Dangling else Rule

Correct Answer: (B)

[EN] In Decision Making: Simple if, if-else, Nested if-else, 'Simple if Statement' handles 'Runs body only when scalar condition evaluates non-zero' (Trailing semicolon if(cond); creates empty body).

[HI] Decision Making: Simple if, if-else, Nested if-else में 'Simple if Statement' का कार्य/विवरण 'Runs body only when scalar condition evaluates non-zero' (Trailing semicolon if(cond); creates empty body) है।

Q18. Which option accurately describes 'Two-Way if-else' in Decision Making: Simple if, if-else, Nested if-else?

(Decision Making: Simple if, if-else, Nested if-else के संदर्भ में 'Two-Way if-else' की सही विशेषता कौन सी है?)

(A) Pairs else strictly with nearest preceding unmatched if

(B) Runs body only when scalar condition evaluates non-zero

(C) Executes strictly one mutually exclusive branch

(D) Tests conditions top-down stopping at first true match

Correct Answer: (C)

[EN] 'Two-Way if-else' provides 'Executes strictly one mutually exclusive branch' — key point: Placing condition directly after else causes compile error.

[HI] 'Two-Way if-else' का मुख्य विवरण 'Executes strictly one mutually exclusive branch' है (Placing condition directly after else causes compile error)।

Q19. In Decision Making: Simple if, if-else, Nested if-else, identify the correct parameter for the specification: "Tests conditions top-down stopping at first true match".

(Decision Making: Simple if, if-else, Nested if-else में "Tests conditions top-down stopping at first true match" विवरण किस विकल्प के लिए सही है?)

(A) Dangling else Rule

(B) Two-Way if-else

(C) Simple if Statement

(D) else-if Multi-Way Ladder

Correct Answer: (D)

[EN] 'else-if Multi-Way Ladder' corresponds to 'Tests conditions top-down stopping at first true match' (Broader top check shadows narrower lower check).

[HI] 'else-if Multi-Way Ladder' का संबंध 'Tests conditions top-down stopping at first true match' (Broader top check shadows narrower lower check) से है।

Q20. Considering Decision Making: Simple if, if-else, Nested if-else, what key behavior defines 'Dangling else Rule'?

(Decision Making: Simple if, if-else, Nested if-else में 'Dangling else Rule' की मुख्य भूमिका या मान क्या है?)

(A) Runs body only when scalar condition evaluates non-zero

(B) Tests conditions top-down stopping at first true match

(C) Pairs else strictly with nearest preceding unmatched if

(D) Executes strictly one mutually exclusive branch

Correct Answer: (C)

[EN] 'Dangling else Rule' represents 'Pairs else strictly with nearest preceding unmatched if' (Visual indentation misleads reader about compiler binding).

[HI] 'Dangling else Rule' का अर्थ/मान 'Pairs else strictly with nearest preceding unmatched if' है (Visual indentation misleads reader about compiler binding)।

Decision Making: Simple if, if-else, Nested if-else — Exam FAQs

Q1: How does C resolve the Dangling Else ambiguity without braces?

बिना `{}` ब्रैकेट के डैंगलिंग एल्स (Dangling Else) समस्या को C कंपाइलर कैसे हल करता है?

[EN] ISO C binds every `else` unconditionally to the nearest preceding unmatched `if`, ignoring visual indentation. Always enclose nested `if` blocks in `{}` so both the compiler and human readers interpret the intended pairing identically.

[HI] ISO C में प्रत्येक `else` इंडेंटेशन की परवाह किए बिना अपने ठीक पहले वाले निकटतम अन-मैच्ड `if` से जुड़ता है। अस्पष्टता हटाने के लिए हमेशा नेस्टेड `if` में `{}` ब्रैकेट लगाएँ।

Q2: Why did `if (x > 10); { printf("Hi"); }` still print "Hi" when `x` was 5?

`x` का मान 5 होने पर भी `if (x > 10); { printf("Hi"); }` ने "Hi" क्यों प्रिंट किया?

[EN] The stray semicolon `;` right after `if (x > 10)` forms a null statement that completes the `if` statement prematurely. The subsequent `{ printf("Hi"); }` becomes an ordinary standalone compound block that runs unconditionally.

[HI] `if (x > 10)` के ठीक बाद लगा `;` एक खाली स्टेटमेंट मानकर `if` को वहीं खत्म कर देता है, जिससे आगे लिखा `{ printf("Hi"); }` एक स्वतंत्र ब्लॉक बनकर हमेशा निष्पादित हो जाता है।

Q3: Why should even single-line `if` and `else` bodies use `{}` curly braces?

एक ही लाइन वाले `if` और `else` में भी `{}` कर्ली ब्रेसेस लगाना क्यों आवश्यक माना जाता है?

[EN] Adding a second statement later—or using a multi-statement macro—without adding braces leaves the extra line running unconditionally outside the `if`, causing notorious bugs like the SSL `goto fail` vulnerability and dangling-else traps.

[HI] बाद में कोई दूसरी लाइन या मैक्रो जोड़ने पर बिना ब्रैकेट के वह लाइन `if` के बाहर रहकर बिना शर्त चल सकती है, जिससे 'goto fail' और डैंगलिंग-एल्स जैसी गंभीर त्रुटियाँ पैदा होती हैं।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)