If statement in C language | C programming in Hindi


Programming में सबसे ज्यादा उपयोग में आने वाली statement if statement ही होती हैं जो की programming करते समय बहुत ज्यादा उपयोग में लायी जाती हैं । इस Tutorial में हम C programming में if statement के बारे में समझेंगे और सीखेंगे । 

If statement in C language | If condition  | Hindi 

If statement को if condition भी कहा जाता हैं क्यूकी इसको केवल एक ही कंडिशन के लिए उपयोग में लाया जाता हैं यदि condition true हैं तो if block में जो भी code होता हैं execute होता हैं और यदि condtion false होती हैं तो if block का कोड़ execute नही होगा । 
Syntax – 

if (condition) {
   Statements (Code will be executed when the condition is true );
   If Block of code 
}

या हिन्दी में syntax लिखे तो – 

if (condition) {
  कोड लाइन (कोड तब execute होता हैं जब if condition सही होती हैं मतलब true);
}

if statement  का उपयोग तब किया जाता है जब एक condition true हो । यदि आप केवल एक ही condition के लिए use करना चाहते हैं तो आप  C programming में if statement का उपयोग कर सकते हैं if condition में आप कोई भी condition बना कर कोई भी काम(task) करा सकते हैं लेकिन यहाँ पर आप सिर्फ एक ही काम(एक ही कोड ऑफ़ ब्लॉक को execute करना ) करा सकते हैं वो भी सिर्फ एक ही condition पर । Control statements में true और false बहुत ही महत्वपूर्ण होते हैं  ।यदि condition true हो जाती हैं तो ही code execute(कोड रन होना ,आउटपुट देना ) होगा यदि false हो जाती हैं तो code execute नहीं होगा उसके लिए अलग control statements का उपयोग करेंगे । तो if condition में यदि आपकी बनाई हुई condition true हो जाती हैं तो आपका कोड execute (code of block) हो जाता है
चलिये C program से समझते हैं 

Examples of if statement in C Programming – 

Example 1 – 

#include <stdio.h>
void main() {
     int a=12; 
     if(a<16)
     {
        printf("a is less than 16 . "); // execute statements 
     }
}

Output – 

a is less than 16 .

उपर दिये गए उदाहरण में एक condition बनाई हैं की यदि variable a का मान(value) 16 से बड़ा हैं तो a is less than 16 ऐसा print होके आए । 
हमने इस C program में variable a को 12 वैल्यू  दी हैं मतलब variable की initial वैल्यू 12 हैं और कंडिशन मैं यह ह की variable a 16 से छोटा हैं तो बिलकुल सही हैं कंडिशन true हैं क्यूकी 12 number तो 16 नंबर से छोटा ही हैं । 
इस तरह से यदि देखे तो condition true हो गयी और जो if block में code line या कह सकते हैं statement होती हैं execute हो जाती हैं । 
अब इसी example के द्वारा false condition को समझते हैं । 
Example 2 – जब if condition false हो तब क्या होगा । 

#include <stdio.h>
void main() {
     int a=12; 
     if(a>16)
     {
        printf("a is less than 16 . "); // execute statements  
     }
     printf(" This is outside statement | another code line."); 
}

Output – 

This is outside statement | another code line.

इस उदाहरण में आप देख सकते हैं हमने less than की जगह > greater than का operator दिया हैं ।  C operators वाले tutorial में हमने greater than > operator के बारे मे सीखा था ।
a>16 – इस condition का मतलब हैं a variable कम मान(value) 16 से बड़ा हैं पर यदि आप देखोगे तो क्या a का मान बड़ा हैं तो 12>16 मतलब क्या 12 नंबर , 16 number से बड़ा हैं ? 
नही , तो इसका मतलब या कंडिशन false हो गयी और जो if block में कोड़ हैं वो execute नही हुआ हैं क्यूकी कंडिशन हमारी false हो गयी हैं । 
लास्ट में if block के बाद जो code line थी वो execute हो गयी क्यूकी वो if block में नही हैं । 
बिलकुल साधारण सी भाषा में यदि condition true होती हैं तो if block के अंदर जितना भी कोड़ होता हैं  execute होगा और  यदि condition false होती हैं तो if block में जितना भी कोड़ कुछ भी रन नही होगा क्यूकी हमने पहले ही condition पर set कर दिया हैं की यदि true होती तो चले नही तो कुछ न चले । 
तो आप समझ गए होंगे की if statement का C programming में किस तरह से उपयोग किया जाता हैं । इससे अगले tutorial में हम if else statement के बारे में सीखेंगे जो की if stetment का additional पार्ट हैं । 


Please Share

Recommended Posts:-