Q.1 What is an Operator in C? Explain Arithmetic, Logical and Bitwise Operators with suitable example.
Operator in C क्या है?
Operator वह symbol (चिन्ह) है जो variables और values के बीच किसी operation को perform करने के लिए इस्तेमाल होता है।
सिंपल शब्दों में, Operator = काम करवाने वाला चिन्ह।
उदाहरण:
C में Operators के प्रकार:
1️⃣ Arithmetic Operators (गणितीय Operators)
ये numbers पर basic गणित (जोड़, घटाव, गुणा, भाग, modulus) करने के लिए होते हैं।
| Operator | Description | Example | Output |
|---|---|---|---|
| + | Addition (जोड़) | 5 + 3 | 8 |
| - | Subtraction (घटाव) | 5 - 3 | 2 |
| * | Multiplication | 5 * 3 | 15 |
| / | Division (भाग) | 6 / 3 | 2 |
| % | Modulus (शेष) | 5 % 3 | 2 |
Example in C:
2️⃣ Logical Operators (तार्किक Operators)
ये conditions (true/false) को check करने के लिए use होते हैं। Result हमेशा 1 (true) या 0 (false) होता है।
| Operator | Description | Example |
|---|---|---|
| && | AND (दोनों true हों) | (a > 0 && b > 0) |
| ! | NOT (true को false, false को true) | !(a > b) |
Example in C:
3️⃣ Bitwise Operators (बिट स्तर Operators)
ये numbers के binary form में operation करते हैं।
| Operator | Description | Example | Binary Example |
|---|---|---|---|
| & | AND (बिट AND) | 5 & 3 | 0101 & 0011 = 0001 |
| | | OR (बिट OR) | 5 | 3 | 0101 | 0011 = 0111 |
| ^ | XOR (Exclusive OR) | 5 ^ 3 | 0101 ^ 0011 = 0110 |
| ~ | NOT (Complement) | ~5 | ~0101 = 1010 |
| << | Left Shift | 5 << 1 | 0101 << 1 = 1010 |
| >> | Right Shift | 5 >> 1 | 0101 >> 1 = 0010 |
Example in C:
Q.2 What do you understand by Looping statement? Explain its types with suitable example.
Looping Statement क्या है?
Looping Statement वह statement होती है जो किसी काम को बार-बार दोहराने के लिए use की जाती है।
सिंपल शब्दों में, अगर हमें कोई काम कई बार करना है तो हम loop का use करते हैं।
Loop के फायदे:
-
बार-बार code लिखने की जरूरत नहीं।
-
Time बचता है और code clean रहता है।
-
Condition के आधार पर काम automate कर सकते हैं।
C में Loop के प्रकार:
1️⃣ for loop
जब number of iterations पता हो।
Syntax:
Example:
2️⃣ while loop
जब हमें पहले condition check करनी हो।
Syntax:
Example:
3️⃣ do-while loop
जब हमें कम से कम एक बार loop execute करना हो।
इसमें condition last में check होती है।
Syntax:
Example:
Q.3 What is an Array? How we can declare and initialize array? Write a program of One Dimensional Array.
Array क्या है?
Array एक समान type के data का collection होता है।
सिंपल शब्दों में, अगर हमें बहुत सारे एक ही तरह के values (जैसे numbers या characters) store करने हैं तो हम array use करते हैं।
उदाहरण:
Class के 5 छात्रों के marks store करने हैं → array use कर सकते हैं।
Array Declare और Initialize कैसे करते हैं?
-
Declare (घोषित करना)
Example:
-
Initialize (मान देना)
-
Method 1: Declaration के साथ value देना
-
Method 2: बाद में value assign करना
Note: Array index हमेशा 0 से शुरू होता है।
-
marks[0] → पहला element
-
marks[4] → पाँचवाँ element
One Dimensional Array Program
Output:
Q.4 What is Function in C? Explain in briefly.
Function क्या है?
Function एक self-contained block of code होता है जो किसी specific काम (task) को perform करता है।
सिंपल शब्दों में, Function = एक छोटा program जो एक काम करता है और उसे बार-बार use किया जा सकता है।
Function क्यों इस्तेमाल करते हैं?
-
Code को reuse कर सकते हैं → बार-बार लिखने की जरूरत नहीं।
-
Program organized और readable बनता है।
-
Problem को small parts में divide कर सकते हैं।
C में Function के प्रकार:
-
User Defined Function (User ने बनायी) – जैसे calculator program में add, subtract function।
-
Built-in Function (C की predefined) – जैसे printf(), scanf(), sqrt(), strlen()।
Function का Syntax:
Components:
-
return_type → function क्या return करेगा (int, float, char, void)
-
function_name → function का नाम
-
parameters → input values (optional)
-
body → statements जो काम perform करते हैं
Example of a Function in C:
Output:
Q.5 What do you mean by Structure? Write the differences between Structure and Union.
Structure क्या है?
Structure C प्रोग्रामिंग की एक user-defined data type है, जिसका उपयोग हम एक ही नाम के तहत अलग-अलग data types के डेटा को संग्रहित करने के लिए करते हैं।
Syntax (उदाहरण सहित):
Explanation:
-
struct Student नाम की structure बनायी।
-
इसमें int, char[], float जैसे अलग-अलग type के data शामिल हैं।
-
हम structure का object s1 बनाकर सभी values assign कर सकते हैं।
Structure और Union में अंतर
| Features | Structure | Union |
|---|---|---|
| Memory Allocation | सभी members के लिए अलग-अलग memory allocate होती है। | सभी members के लिए same memory location share होती है। |
| Size | Structure का size सभी members के size का sum होता है। | Union का size सबसे बड़े member के size के बराबर होता है। |
| Access | एक साथ सभी members को access किया जा सकता है। | एक समय में केवल एक member को access किया जा सकता है। |
| Use Case | जब हमें सभी members की values store करनी हो। |