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 = काम करवाने वाला चिन्ह।

उदाहरण:

int a = 5, b = 3; int sum = a + b; // '+' एक Operator है जो जोड़ (Addition) करता है

C में Operators के प्रकार:

1️⃣ Arithmetic Operators (गणितीय Operators)

ये numbers पर basic गणित (जोड़, घटाव, गुणा, भाग, modulus) करने के लिए होते हैं।

OperatorDescriptionExampleOutput
+Addition (जोड़)5 + 38
-Subtraction (घटाव)5 - 32
*Multiplication5 * 315
/Division (भाग)6 / 32
%Modulus (शेष)5 % 32

Example in C:

#include <stdio.h> int main() { int a = 10, b = 3; printf("Addition: %d\n", a + b); printf("Subtraction: %d\n", a - b); printf("Multiplication: %d\n", a * b); printf("Division: %d\n", a / b); printf("Modulus: %d\n", a % b); return 0; }

2️⃣ Logical Operators (तार्किक Operators)

ये conditions (true/false) को check करने के लिए use होते हैं। Result हमेशा 1 (true) या 0 (false) होता है।

OperatorDescriptionExample
&&AND (दोनों true हों)(a > 0 && b > 0)
!NOT (true को false, false को true)!(a > b)

Example in C:

#include <stdio.h> int main() { int a = 5, b = 0; if(a > 0 && b == 0) printf("Both conditions true\n"); if(a > 0 || b > 0) printf("At least one condition true\n"); if(!(a < b)) printf("Condition is false, so NOT = true\n"); return 0; }

3️⃣ Bitwise Operators (बिट स्तर Operators)

ये numbers के binary form में operation करते हैं।

OperatorDescriptionExampleBinary Example
&AND (बिट AND)5 & 30101 & 0011 = 0001
|OR (बिट OR)5 | 30101 | 0011 = 0111
^XOR (Exclusive OR)5 ^ 30101 ^ 0011 = 0110
~NOT (Complement)~5~0101 = 1010
<<Left Shift5 << 10101 << 1 = 1010
>>Right Shift5 >> 10101 >> 1 = 0010

Example in C:

#include <stdio.h> int main() { int a = 5, b = 3; printf("a & b = %d\n", a & b); printf("a | b = %d\n", a | b); printf("a ^ b = %d\n", a ^ b); printf("~a = %d\n", ~a); printf("a << 1 = %d\n", a << 1); printf("a >> 1 = %d\n", a >> 1); return 0; }

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:

for(initialization; condition; increment/decrement) { // statements }

Example:

#include <stdio.h> int main() { int i; for(i = 1; i <= 5; i++) { printf("%d\n", i); // 1 से 5 तक print करेगा } return 0; }

2️⃣ while loop

जब हमें पहले condition check करनी हो।

Syntax:

while(condition) { // statements }

Example:

#include <stdio.h> int main() { int i = 1; while(i <= 5) { printf("%d\n", i); i++; // increment करना जरूरी है वरना infinite loop } return 0; }

3️⃣ do-while loop

जब हमें कम से कम एक बार loop execute करना हो।
इसमें condition last में check होती है।

Syntax:

do { // statements } while(condition);

Example:

#include <stdio.h> int main() { int i = 1; do { printf("%d\n", i); // पहले execute करेगा फिर condition check i++; } while(i <= 5); return 0; }

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 कैसे करते हैं?

  1. Declare (घोषित करना)

data_type array_name[size];

Example:

int marks[5]; // 5 students के marks store करने के लिए integer array
  1. Initialize (मान देना)

  • Method 1: Declaration के साथ value देना

int marks[5] = {80, 75, 90, 85, 70};
  • Method 2: बाद में value assign करना

marks[0] = 80; marks[1] = 75; marks[2] = 90; marks[3] = 85; marks[4] = 70;

Note: Array index हमेशा 0 से शुरू होता है।

  • marks[0] → पहला element

  • marks[4] → पाँचवाँ element

One Dimensional Array Program

#include <stdio.h> int main() { int marks[5] = {80, 75, 90, 85, 70}; int i; printf("Students Marks:\n"); for(i = 0; i < 5; i++) { printf("Student %d: %d\n", i+1, marks[i]); } return 0; }

Output:

Students Marks: Student 1: 80 Student 2: 75 Student 3: 90 Student 4: 85 Student 5: 70

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:

return_type function_name(parameters) { // statements return value; // अगर return_type void है तो return optional }

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:

#include <stdio.h> // User defined function to add two numbers int add(int a, int b) { return a + b; } int main() { int sum; sum = add(5, 3); // function call printf("Sum = %d", sum); return 0; }

Output:

Sum = 8

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 (उदाहरण सहित):

#include <stdio.h> struct Student { int roll; // integer type char name[20]; // string type float marks; // float type }; int main() { struct Student s1 = {1, "Sonu", 85.5}; printf("Roll: %d\nName: %s\nMarks: %.2f", s1.roll, s1.name, s1.marks); return 0; }

Explanation:

  • struct Student नाम की structure बनायी।

  • इसमें int, char[], float जैसे अलग-अलग type के data शामिल हैं।

  • हम structure का object s1 बनाकर सभी values assign कर सकते हैं।

Structure और Union में अंतर

FeaturesStructureUnion
Memory Allocationसभी members के लिए अलग-अलग memory allocate होती है।सभी members के लिए same memory location share होती है।
SizeStructure का size सभी members के size का sum होता है।Union का size सबसे बड़े member के size के बराबर होता है।
Accessएक साथ सभी members को access किया जा सकता है।एक समय में केवल एक member को access किया जा सकता है।
Use Caseजब हमें सभी members की values store करनी हो।

🧩 Q.6 Explain Array with Structure with

Suitable Example

जब हमें एक ही तरह के कई students, employees या items के डेटा को store करना हो,
तो हम Structure का Array use करते हैं।

यह एक ऐसा array होता है, जिसमें हर element एक structure object होता है।

💻 Syntax और Example

#include <stdio.h> // Structure define करना struct Student { int roll; char name[20]; float marks; }; int main() { // Structure का Array बनाना struct Student s[3]; // 3 students के लिए array // Data input करना for(int i = 0; i < 3; i++) { printf("Enter Roll, Name and Marks of Student %d: ", i+1); scanf("%d %s %f", &s[i].roll, s[i].name, &s[i].marks); } // Data Output करना printf("\nStudent Details:\n"); for(int i = 0; i < 3; i++) { printf("Roll: %d, Name: %s, Marks: %.2f\n", s[i].roll, s[i].name, s[i].marks); } return 0; }

🖥️ Output (Conceptual):

Enter Roll, Name and Marks of Student 1: 101 Ravi 85 Enter Roll, Name and Marks of Student 2: 102 Sita 90 Enter Roll, Name and Marks of Student 3: 103 Aman 80 Student Details: Roll: 101, Name: Ravi, Marks: 85.00 Roll: 102, Name: Sita, Marks: 90.00 Roll: 103, Name: Aman, Marks: 80.00

🧠 Q.7 Write Notes On:

a) Pointer definition and example.

Pointer एक ऐसा special variable है जो किसी दूसरे variable के memory address को store करता है।

सामान्य variable value store करता है,
लेकिन Pointer उस value के address को store करता है।


🔸 Pointer का Example

#include <stdio.h> int main() { int a = 10; // Normal variable int *p; // Pointer declaration p = &a; // Pointer में a का address store printf("Value of a: %d\n", a); printf("Address of a: %p\n", &a); printf("Value using pointer: %d\n", *p); *p = 20; printf("Updated value of a: %d\n", a); return 0; }

🖥️ Output (Conceptual):

Value of a: 10 Address of a: 0x7ffee4b89c4c Value using pointer: 10 Updated value of a: 20

🔸 Pointer के मुख्य प्रकार

  • Null Pointer → किसी memory location को point नहीं करता

  • Void Pointer → किसी भी type के data को point कर सकता है

  • Dangling Pointer → Invalid या deleted memory को point करता है

  • Wild Pointer → Initialize नहीं किया गया pointer



(i) malloc() – Memory Allocation

Full Form: Memory Allocation
Purpose: Runtime पर memory allocate करने के लिए use किया जाता है।

यह memory को initialize नहीं करता (garbage values होती हैं)।

pointer = (cast_type*) malloc(size_in_bytes);

Features:

  • केवल memory allocate करता है

  • Memory allocation fail होने पर NULL return करता है


(ii) calloc() – Contiguous Allocation

Full Form: Contiguous Allocation
Purpose: Memory allocate करता है और उसे zero से initialize

करता है।

pointer = (cast_type*) calloc(number_of_elements, size_of_each_element);

Features:

  • Memory allocate + initialize दोनों करता है

  • Failure पर NULL return करता है


📁 Q.8 Explain File Handling in C


File एक permanent storage का तरीका है, जहाँ data को computer

की memory
(जैसे hard disk या SSD) में store किया जाता है।
Program बंद होने के बाद भी data सुरक्षित रहता है।

🔸 File Handling की जरूरत क्यों है?

  • Data को लंबे समय तक save करने के लिए

  • Program बंद होने के बाद भी access करने के लिए

  • Multiple programs के बीच data share करने के लिए


⚙️ C में File Handling के 4 Steps

1️⃣ File Open करना

FILE *fp; fp = fopen("filename.txt", "mode");
ModeMeaning
"r"Read
"w"Write (create/overwrite)
"a"Append
"r+"Read + Write
"w+"Write + Read
"a+"Append + Read

2️⃣ File में Data Write करना

fprintf(fp, "Hello World\n"); fputs("This is C programming.", fp);

3️⃣ File से Data Read करना

fscanf(fp, "%d", &num); fgets(str, 100, fp);

4️⃣ File Close करना

fclose(fp);

📂 Q.9 Why do we Need File Handling in C? How

Many Types of File in C?

सामान्य variables या arrays program बंद होने के बाद data खो देते हैं।
File Handling की मदद से हम data को permanently store कर सकते हैं।

✅ मुख्य जरूरतें:

  • Permanent Storage
  • Large Data Handling
  • Data Sharing
  • Data Management
  • Input/Output Flexibility


🔹 2. C में Files के प्रकार

(i) Text File (पाठ फ़ाइल)

Data characters के रूप में store होता है

Human-readable (Notepad में देखा जा सकता है)


  • Examples: .txt, .c, .cpp, .csv

Functions:

Read → fscanf(), fgets()

Write → fprintf(), fputs()

(ii) Binary File (बाइनरी फ़ाइल)

  • Data binary format (0 और 1) में store होता है

  • Human-readable नहीं होता
    Examples: .dat, .bin, .mp3, .jpg

Functions:

  • Read → fread()

  • Write → fwrite()


🧾 Q.10 Explain the File Operations in C

with Examples

C में file operations का उपयोग file को create, read, write,

update और close करने के लिए किया जाता है।

🔸 1. File Open करना

FILE *fp; fp = fopen("filename.txt", "mode");
ModePurpose
"r"    Read existing file
"w"Write new file or overwrite
"a"Append data at end
"r+"Read + Write existing file
"w+"Write + Read new file
"a+"Append + Read

🔸 2. File में Data Write करना

fprintf(fp, "Hello World\n"); fputs("This is C Programming.", fp);
  • fprintf() → formatted data write करता है

  • fputs() → simple string write करता है

🔸 3. File से Data Read करना

fscanf(fp, "%d", &num); fgets(str, 100, fp);
  • scanf() → formatted data read करता है

  • fgets() → line read करता है

🔸 4. File Close करना

fclose(fp);

File को हमेशा close करना जरूरी होता है ताकि data properly save हो जाए।