Decision Making In C In Hindi – if, if-else, switch, break और goto स्टेटमेंट्स हिंदी में पूरी जानकारी

1. Decision Making In C In Hindi – Introduction

दोस्तों, इस आर्टिकल में हम स्टेप-बाय-स्टेप समझेंगे कि decision making in C in Hindi क्या होती है।इसमें हम if, if-else, nested if, switch, break और goto जैसे स्टेटमेंट्स को असली उदाहरणों के साथ विस्तार से जानेंगे।

दोस्तों, C में decision making का मतलब होता है

Flowchart diagram showing different types of conditional statements in C language including if, if-else, nested if, switch, break, and goto with examples.
Visual overview of Decision Making statements in C – includes if, if-else, nested if, switch, break, and goto for beginner-level understanding.

दोस्तों, C में decision making का मतलब होता है प्रोग्राम को condition के आधार पर तय करना कि कौन सा कोड ब्लॉक चलेगा। सरल शब्दों में, जब कोई condition true हो तो एक खास कोड ब्लॉक चले, और जब false हो तो कोई दूसरा कोड ब्लॉक चले।

दोस्तों, इस पूरे आर्टिकल में हम हर एक स्टेटमेंट को:

  • रियल लाइफ उदाहरणों के साथ
  • सरल और समझने में आसान हिंदी के explanation के साथ
  • कोड और उसके आउटपुट के फॉर्मेट में
    इस तरह समझाएंगे ताकि beginner भी बिना किसी confusion के C में decision making को आसानी से समझ सकें।

2. if Statement in C – C में if स्टेटमेंट

दोस्तों if स्टेटमेंट का इस्तेमाल तब किया जाता है, जब हमें किसी शर्त (condition) के true होने पर ही कोई कोड ब्लॉक चलाना हो।

सिंटैक्स:

if (condition) {

    // जब condition true हो, तो यह कोड चलेगा
}

उदाहरण:

if (a > 0) 
{
  printf("Positive number");
}

दोस्तों ऊपर दिए गए उदाहरण में, अगर a की वैल्यू 0 से बड़ी है, तो आउटपुट होगा “Positive number”


3. if else Statement In C In Hindi – C में if-else स्टेटमेंट

दोस्तों, if-else स्टेटमेंट का इस्तेमाल तब किया जाता है जब हमें एक ही condition के आधार पर दो अलग-अलग कोड ब्लॉक चलाने हों:

  • अगर condition true हो, तो पहला ब्लॉक चलेगा
  • अगर condition false हो, तो दूसरा ब्लॉक चलेगा

सिंटैक्स:

if (condition) {

     // अगर condition true है तो यह कोड चलेगा

} else {

   // अगर condition false है तो यह कोड चलेगा

}

उदाहरण:

int a = -3;

if (a > 0) {

    printf("Positive");

} else {

    printf("Non-positive");

}

आउटपुट: Non-positive

दोस्तों, यहाँ a की वैल्यू -3 है, जो कि पॉज़िटिव नहीं है। इसलिए else ब्लॉक का कोड चला और आउटपुट मिला “Non-positive”


4. Nested if else Statement In C In Hindi – C में Nested if-else

दोस्तों जब एक if-else के अंदर ही दूसरा if-else लिखा जाता है, तो उसे nested if-else कहा जाता है।

सिंटैक्स:

if (condition1) {

   if (condition2) {

      // जब दोनों conditions true हों, तब यह कोड चलेगा

   }

}

उदाहरण:

int a = 12;

if (a > 0) {

    if (a > 10) {

        printf("Greater than 10");

    } else {

        printf("Less than or equal to 10");

    }
}

आउटपुट: Greater than 10

दोस्तों यहाँ a की वैल्यू 12 है।

  • पहली condition a > 0 true है।
  • दूसरी condition a > 10 भी true है।

इसलिए आउटपुट आया “Greater than 10”


5. Multiple if Conditions in C – C में Multiple if Conditions

जब आपको अलग-अलग conditions को independently (स्वतंत्र रूप से) चेक करना हो, तब multiple if का इस्तेमाल किया जाता है। यानी, हर if स्टेटमेंट अपनी condition को अलग से चेक करता है।

सिंटैक्स:

if (condition1) {

   // जब condition1 true हो

}
if (condition2) {

   // जब condition2 true हो

}

उदाहरण:

int a = 5;

if (a > 0)

    printf("Positive\n");

if (a < 10)

    printf("Less than 10\n");

आउटपुट:

Positive
Less than 10

दोस्तों यहाँ:

  • पहली condition a > 0 true है, इसलिए “Positive” प्रिंट हुआ।
  • दूसरी condition a < 10 भी true है, इसलिए “Less than 10” भी प्रिंट हुआ।

6. switch Statement In C In Hindi – C में switch स्टेटमेंट

जब हमें किसी expression की वैल्यू के आधार पर कई conditions चेक करनी हों, तब switch स्टेटमेंट का इस्तेमाल किया जाता है। यह if-else का एक बेहतरीन विकल्प है और तब ज़्यादा readable (आसानी से पढ़ने योग्य) होता है जब बहुत सारे options हों।

सिंटैक्स:

switch (expression) {

    case value1:

        // जब expression का result value1 हो

        break;

    case value2:

        // जब expression का result value2 हो

        break;

    default:

        // जब कोई भी case match न करे
}

उदाहरण:

#include <stdio.h>

int main() {

    int num1, num2;

    char operator;

    // Calculator का मेन्यू दिखाना
    printf("Simple Calculator\n");

    printf("------------------\n");

    printf("Choose an operation (+, -, *, /): ");

    scanf(" %c", &operator);  // %c से पहले space ताकि newline issue न हो

    // यूज़र से दो numbers लेना
    printf("Enter two integers:\n");

    printf("First number: ");

    scanf("%d", &num1);

    printf("Second number: ");

    scanf("%d", &num2);

    // Switch statement के ज़रिए operation perform करना
    switch(operator) {

        case '+':

            printf("Result: %d + %d = %d\n", num1, num2, num1 + num2);

            break;

        case '-':

            printf("Result: %d - %d = %d\n", num1, num2, num1 - num2);

            break;

        case '*':

            printf("Result: %d * %d = %d\n", num1, num2, num1 * num2);

            break;

        case '/':

            if (num2 != 0) {

                printf("Result: %d / %d = %d\n", num1, num2, num1 / num2);

            } else {

                printf("Error: Division by zero is not allowed.\n");

            }

            break;

        default:

            printf("Invalid operator! Please enter one of (+, -, *, /).\n");

            break;

    }

    return 0;

}

7. break And goto Statement In C In Hindi – C में break और goto (Flow Control)

break स्टेटमेंट:

दोस्तों break स्टेटमेंट का इस्तेमाल loop या switch-case से तुरंत बाहर निकलने के लिए किया जाता है।

जब भी कोई condition true होती है, तो break स्टेटमेंट उस loop या switch-case को तुरंत exit कर देता है, और प्रोग्राम का नियंत्रण (control) अगले हिस्से पर चला जाता है।

उदाहरण:


#include <stdio.h>

int main() {
    for (int i = 1; i <= 10; i++) {
        if (i == 5) {
            break; // Jab i 5 hoga, loop turant ruk jaayega
        }
        printf("%d\n", i);
    }
    printf("Loop ended.\n");
    return 0;
}

याद रखने वाली बात:

  • break स्टेटमेंट ज़्यादातर loops (for, while, do-while) और switch-case के अंदर ही इस्तेमाल होता है।
  • जैसे ही break execute होता है, प्रोग्राम तुरंत उस ब्लॉक से बाहर आ जाता है।

goto स्टेटमेंट:

दोस्तों goto स्टेटमेंट के जरिए प्रोग्राम का control एक labelled part पर सीधे jump कर सकता है।

इसका इस्तेमाल कभी-कभी किया जाता है, लेकिन इसे ज़्यादा use करना recommended नहीं है, क्योंकि इससे कोड की readability और maintainability कम हो सकती है।

सिंटैक्स:

goto label_name;
// ...

label_name:

   // Statements;

उदाहरण:

दोस्तों यह प्रोग्राम यूज़र से एक number input लेने के लिए कहता है। अगर number negative होता है, तो यह एक labelled section पर jump करता है जो यूज़र से फिर से एक positive number दर्ज करने के लिए कहता है।


#include <stdio.h>

int main() {
    int num;

     // Label जहां jump होगा
    start:
    printf("Enter a positive number: ");
    scanf("%d", &num);

    if (num < 0) {
        printf("You entered a negative number. Please try again.\n");
        goto start; // वापस label पर jump
    }

    printf("You entered: %d\n", num);
    return 0;
}

आउटपुट:

Enter a positive number: -3
You entered a negative number. Please try again.
Enter a positive number: 5
You entered: 5


8. (FAQs) – अक्सर पूछे जाने वाले सवाल

1. C में if स्टेटमेंट क्या है?

अगर condition true हो, तो if स्टेटमेंट एक कोड ब्लॉक को execute करता है।

2. C में if-else स्टेटमेंट क्या है?

अगर condition true हो, तो एक कोड ब्लॉक चलेगा, वरना दूसरा कोड ब्लॉक execute होगा।

3. C में nested if-else क्या है?

Nested if-else का मतलब है Statement के अंदर Statement
सीधे शब्दों में कहें तो, जब एक if-else के अंदर दूसरा if-else लिखा जाए, तो उसे nested if-else कहते हैं। आप कई nested if-else statements लिख सकते हैं।

उदाहरण:

include<stdio.h>
int main() {
int marks;
printf(“Enter your marks: “);
scanf(“%d”, &marks);
if (marks >= 40) {
if (marks >= 75) {
printf("You passed with distinction!");
} else {
printf("You passed!"); }
} else { printf("You failed.");
}
return 0;
}

आउटपुट:
Enter your marks: 80
You passed with distinction!

4. C में switch स्टेटमेंट क्या है?

जब किसी expression की वैल्यू के आधार पर कई conditions चेक करनी हों, तो switch स्टेटमेंट का इस्तेमाल किया जाता है।

5. C में break स्टेटमेंट क्या है?

Loops में, break स्टेटमेंट current iteration को रोककर loop से बाहर निकल जाता है।
Switch-case में, break current case को खत्म कर अगला case चलने से रोकता है।

6. C में goto स्टेटमेंट क्या है?

goto स्टेटमेंट का इस्तेमाल प्रोग्राम में सीधे किसी labeled statement पर jump करने के लिए किया जाता है। यह unconditional control transfer देता है, जिससे प्रोग्राम किसी कोड ब्लॉक को skip या repeat कर सकता है।

सीधे शब्दों में कहें तो, goto प्रोग्राम का control एक labelled हिस्से पर भेज देता है।


इसे भी पढ़े –


9. निष्कर्ष (Conclusion)

दोस्तों, इस आर्टिकल में हमने C language के decision making statements जैसे if, if-else, nested if-else, switch, break, और goto को विस्तार से समझा।
हर concept को real-life example, आसान हिंदी व्याख्या और output के साथ कवर किया — ताकि कोई भी beginner इसे आसानी से समझ सके और confidently इस्तेमाल कर सके।

दोस्तों, अगर आपको यह आर्टिकल मददगार लगा हो तो इसे share करें, comment करें और अपने दोस्तों को भी recommend करें।
अगला आर्टिकल किस topic पर चाहिए? Comment करके ज़रूर बताएं।

Written by: Aditya (Programming Sikho)

Spread the love

Leave a Comment