Mostly Asked C Programming Questions – Operators & Loops (Top 12)
Q1. What are arithmetic, relational, and logical operators in C?C में अंकगणितीय, रिलेशनल और लॉजिकल ऑपरेटर क्या हैं?
Arithmetic operators perform basic math operations: + (add), - (subtract), * (multiply), / (divide), % (modulus). Relational operators compare two values and return true (1) or false (0), like ==, !=, >, <, >=, <=. Logical operators combine conditions: && (AND), || (OR), ! (NOT).
अंकगणितीय ऑपरेटर मूल गणितीय ऑपरेशन करते हैं: + (जोड़), - (घटाव), * (गुणा), / (भाग), % (मॉड्यूलस)। रिलेशनल ऑपरेटर दो मानों की तुलना करते हैं और सही (1) या गलत (0) लौटाते हैं, जैसे ==, !=, >, <, >=, <=। लॉजिकल ऑपरेटर स्थितियों को जोड़ते हैं: && (और), || (या), ! (नहीं)।
Q2. Difference between =, ==, and != operators in C?C में =, ==, और != ऑपरेटर में क्या अंतर है?
= is the assignment operator used to assign a value to a variable. == is the equality operator used to compare two values for equality. != is the inequality operator, true when values differ.
int a = 5; // assignment if(a == 5) { /* true if a equals 5 */ } if(a != 3) { /* true if a is not 3 */ }
= असाइनमेंट ऑपरेटर है जो किसी वेरिएबल को मान असाइन करता है। == तुलना ऑपरेटर है जो दो मानों की समानता जांचता है। != असमानता ऑपरेटर है, जो तब सही होता है जब मान अलग हों।
int a = 5; // असाइनमेंट if(a == 5) { /* सही यदि a 5 के बराबर है */ } if(a != 3) { /* सही यदि a 3 के बराबर नहीं है */ }
Q3. What are increment and decrement operators?इन्क्रीमेंट और डिक्रीमेंट ऑपरेटर क्या हैं?
Increment (++) increases an integer variable by 1; decrement (--) decreases it by 1. Can be used as prefix (++a) or postfix (a++).
Example:
int x = 10; ++x; // x becomes 11 x--; // x becomes 10 again
इन्क्रीमेंट (++) किसी पूर्णांक वेरिएबल को 1 से बढ़ाता है; डिक्रीमेंट (--) इसे 1 से घटाता है। प्रीफिक्स (++a) या पोस्टफिक्स (a++) में इस्तेमाल किया जा सकता है।
उदाहरण:
int x = 10; ++x; // x 11 हो जाता है x--; // x फिर से 10 हो जाता है
Q4. What is type casting in C?C में टाइप कास्टिंग क्या है?
Type casting converts a variable from one data type to another explicitly. Syntax: (type)variable.
Example:
float f = 3.5; int i = (int)f; // i becomes 3
टाइप कास्टिंग किसी वेरिएबल को एक डेटा प्रकार से दूसरे में स्पष्ट रूप से बदलना है। सिंटैक्स: (type)variable।
उदाहरण:
float f = 3.5; int i = (int)f; // i 3 हो जाता है
Q5. Explain operator precedence and associativity in C.C में ऑपरेटर प्रीसिडेंस और असोसिएटिविटी समझाएं।
Operator precedence determines the order in which operators are evaluated. Associativity defines the direction (left-to-right or right-to-left) for operators with the same precedence.
Example: * has higher precedence than +, so in 3 + 4 * 5, multiplication happens first.
Associativity of + and - is left to right.
ऑपरेटर प्रीसिडेंस यह निर्धारित करता है कि ऑपरेटर किस क्रम में मूल्यांकन किए जाएं। असोसिएटिविटी यह बताती है कि समान प्रीसिडेंस वाले ऑपरेटर किस दिशा में (बाएं से दाएं या दाएं से बाएं) लागू होंगे।
उदाहरण: * की प्रीसिडेंस + से अधिक होती है, इसलिए 3 + 4 * 5 में पहले गुणा होता है।
+ और - की असोसिएटिविटी बाएं से दाएं है।
Q6. How does if, if-else, and switch-case work in C?C में if, if-else, और switch-case कैसे काम करते हैं?
if checks a condition; executes the block if true.
if-else executes one block if true, another if false.
switch-case selects a block to execute based on a variable's value.
Example:
int x = 2; switch(x) { case 1: printf("One"); break; case 2: printf("Two"); break; default: printf("Other"); }
if किसी शर्त की जांच करता है; यदि सही हो तो ब्लॉक निष्पादित करता है।
if-else एक ब्लॉक सही होने पर, दूसरा गलत होने पर निष्पादित करता है।
switch-case एक वेरिएबल के मान के आधार पर ब्लॉक चुनता है।
उदाहरण:
int x = 2; switch(x) { case 1: printf("One"); break; case 2: printf("Two"); break; default: printf("Other"); }
Q7. What do break, continue, and goto statements do?break, continue, और goto स्टेटमेंट क्या करते हैं?
break
exits a loop or switch.continue
skips current iteration and jumps to next loop cycle.goto
jumps to a labeled statement anywhere in the function (use sparingly).
break
लूप या स्विच से बाहर निकलता है।continue
वर्तमान चक्र को छोड़कर अगले लूप चक्र पर जाता है।goto
किसी लेबल्ड स्टेटमेंट पर कूदता है (ध्यान से इस्तेमाल करें)।
Q8. Explain working of switch-case statement.switch-case स्टेटमेंट कैसे काम करता है?
switch evaluates an integer or char expression and jumps to matching case label. Without break
, execution continues to next case (fall-through).
Use default
for unmatched cases.
Example:
switch(day) { case 1: printf("Sunday"); break; case 2: printf("Monday"); break; default: printf("Invalid day"); }
switch किसी पूर्णांक या अक्षर अभिव्यक्ति का मूल्यांकन करता है और मेल खाने वाले case लेबल पर कूदता है। यदि break
न हो तो अगले case पर भी चलता रहता है (fall-through)।
मेल न खाने वाले मामलों के लिए default
का उपयोग करें।
उदाहरण:
switch(day) { case 1: printf("Sunday"); break; case 2: printf("Monday"); break; default: printf("Invalid day"); }
Q9. Explain syntax of for loop.for लूप का सिंटैक्स समझाएं।
for loop syntax: for(initialization; condition; update)
It executes the loop block while condition is true, updating after each iteration.
Example:
for(int i = 0; i < 5; i++) { printf("%d\n", i); }
for लूप का सिंटैक्स: for(initialization; condition; update)
यह तब तक लूप ब्लॉक को चलाता है जब तक शर्त सही हो, हर चक्र के बाद अपडेट करता है।
उदाहरण:
for(int i = 0; i < 5; i++) { printf("%d\n", i); }
Q10. Difference between while and do-while loops.while और do-while लूप में क्या अंतर है?
while loop checks the condition before executing the loop block. If false initially, loop body may not execute.
do-while loop executes the block once first, then checks the condition.
Example:
while(x < 5) { /*...*/ } do { /*...*/ } while(x < 5);
while लूप शर्त जांचता है उससे पहले कि लूप ब्लॉक चले। यदि शुरू में शर्त गलत हो तो लूप नहीं चलेगा।
do-while लूप पहले एक बार ब्लॉक चलाता है फिर शर्त जांचता है।
उदाहरण:
while(x < 5) { /*...*/ } do { /*...*/ } while(x < 5);