Binary File Operations: fread() and fwrite() in C Notes in Hindi & English : बाइनरी फाइल्स: fread() और fwrite() द्वारा स्ट्रक्चर रिकॉर्ड्स पढ़ना और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Binary File Operations: fread() and fwrite() in C (बाइनरी फाइल्स: fread() और fwrite() द्वारा स्ट्रक्चर रिकॉर्ड्स पढ़ना) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Binary file operations in C use fread() and fwrite() on streams opened with the "b" flag (such as "rb" or "wb") to transfer raw memory bytes without text translation. This direct block I/O efficiently stores and retrieves fixed-layout structures and numeric arrays while preserving exact bit representations.

अध्याय सार: C में बाइनरी फाइल ऑपरेशन्स "rb" या "wb" जैसे "b" फ्लैग के साथ खोली गई स्ट्रीम्स पर fread() और fwrite() का उपयोग करके बिना टेक्स्ट बदलाव के सीधे मेमोरी बाइट्स ट्रांसफर करते हैं। यह ब्लॉक I/O निश्चित आकार के स्ट्रक्चर्स और न्यूमेरिक ऐरे को सटीक बिट रूप में तेजी से स्टोर और रीस्टोर करता है।

Binary File Operations: fread() and fwrite() in C: Detailed Notes & Architecture (बाइनरी फाइल्स: fread() और fwrite() द्वारा स्ट्रक्चर रिकॉर्ड्स पढ़ना)

1. Text Mode vs Binary Mode File Streams (टेक्स्ट मोड बनाम बाइनरी मोड फाइल स्ट्रीम्स)

[EN] Opening a file without "b" uses text mode, where platforms like Windows translate '\n' (0x0A) to '\r\n' (0x0D 0x0A) on write and reverse it on read, and may treat byte 0x1A (Ctrl+Z) as end-of-file. Binary mode ("rb", "wb", "ab", "rb+", "wb+") disables all character translations so every byte stored in RAM matches the exact bytes written on disk. For example, saving the 4-byte integer 1000000 with fprintf() writes 7 ASCII characters, whereas fwrite() stores it in exactly 4 raw bytes regardless of digit count. Consequently, binary files are compact, fast to parse, and immune to precision loss in IEEE 754 floating-point numbers.

[HI] बिना "b" के फाइल खोलने पर टेक्स्ट मोड लागू होता है, जहाँ Windows जैसे सिस्टम लिखते समय '\n' को '\r\n' में बदलते हैं और बाइट 0x1A को EOF मान सकते हैं। बाइनरी मोड ("rb", "wb", "ab", "rb+", "wb+") सभी कैरेक्टर रूपांतरण बंद कर देता है ताकि RAM और डिस्क पर बाइट्स बिल्कुल समान रहें। उदाहरण के लिए, 4-बाइट पूर्णांक 1000000 को fprintf() से लिखने पर 7 ASCII बाइट्स लगते हैं, जबकि fwrite() इसे हमेशा ठीक 4 रॉ बाइट्स में स्टोर करता है। इस कारण बाइनरी फाइल्स कम जगह लेती हैं, तेज पढ़ी जाती हैं और फ्लोटिंग-पॉइंट प्रिसिशन नहीं खोतीं।

2. Signature and Behavior of fwrite() (fwrite() का सिंटैक्स और कार्यप्रणाली)

[EN] The fwrite() prototype is size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream). Its four parameters specify the source memory address (ptr), the byte size of one element (size, commonly sizeof(struct Rec)), the count of elements to write (nmemb), and the target FILE pointer. Critically, fwrite() returns the number of complete elements written (type size_t), NOT the total byte count unless size is 1. If the returned value is less than nmemb, either a write error occurred or the disk filled up, which can be confirmed via ferror(stream).

[HI] fwrite() का प्रोटोटाइप size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) होता है। इसके चार पैरामीटर स्रोत मेमोरी पता (ptr), एक एलिमेंट का आकार बाइट्स में (size, जैसे sizeof(struct Rec)), एलिमेंट्स की संख्या (nmemb) और लक्ष्य FILE पॉइंटर बताते हैं। ध्यान देने योग्य है कि fwrite() कुल बाइट्स के बजाय सफलतापूर्वक लिखे गए पूर्ण एलिमेंट्स की संख्या (size_t) लौटाता है। यदि रिटर्न मान nmemb से कम हो, तो डिस्क भरने या राइट त्रुटि की पुष्टि ferror(stream) से की जा सकती है।

3. Signature and Behavior of fread() (fread() का सिंटैक्स और कार्यप्रणाली)

[EN] The fread() prototype is size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream). It reads up to size * nmemb raw bytes from stream into the buffer pointed to by ptr and returns the number of complete items of size bytes successfully transferred. When scanning a binary database sequentially, programmers write while (fread(&emp, sizeof(emp), 1, fp) == 1) to process each record cleanly until 0 is returned at EOF. If fread() returns a count smaller than nmemb, calling feof(fp) verifies normal end-of-file while ferror(fp) detects corrupted or truncated stream reads.

[HI] fread() का प्रोटोटाइप size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) होता है। यह स्ट्रीम से size * nmemb बाइट्स तक रॉ डेटा पढ़कर ptr बफर में भरता है और सफलतापूर्वक पढ़े गए पूर्ण रिकॉर्ड्स की संख्या लौटाता है। बाइनरी डेटाबेस को क्रम से पढ़ने के लिए while (fread(&emp, sizeof(emp), 1, fp) == 1) लूप का प्रयोग किया जाता है जो EOF पर 0 मिलते ही रुक जाता है। यदि रिटर्न मान nmemb से कम आए, तो feof(fp) से फाइल अंत और ferror(fp) से रीड त्रुटि की जांच की जाती है।

4. Structure Serialization Pitfalls: Pointers, Padding, and Endianness (स्ट्रक्चर सीरियलाइजेशन की सावधानियां: पॉइंटर्स, पैडिंग और एंडियननेस)

[EN] Writing C structures directly with fwrite() works cleanly only for flat Plain Old Data (POD) structures containing fixed arrays like char name[32] rather than pointer fields like char *name. If a struct holds a pointer, fwrite() saves only the transient virtual memory address, which becomes a dangling garbage pointer when read back in another run. Additionally, compilers insert alignment padding bytes between struct members (so sizeof(struct) may exceed the sum of field sizes), and CPU endianness (little-endian x86 vs big-endian network hardware) differs across architectures. For portable network or cross-platform formats, fields should be serialized individually in fixed endianness rather than dumping raw padded structs.

[HI] fwrite() से सीधे C स्ट्रक्चर लिखना केवल उन स्ट्रक्चर्स के लिए सही काम करता है जिनमें char *name जैसे पॉइंटर्स के बजाय char name[32] जैसे निश्चित ऐरे हों। यदि स्ट्रक्चर में पॉइंटर है, तो fwrite() केवल अस्थायी मेमोरी एड्रेस सेव करेगा जो अगले रन में अमान्य (डैंगलिंग) हो जाएगा। इसके अलावा कंपाइलर मेमोरी अलाइनमेंट के लिए स्ट्रक्चर में पैडिंग बाइट्स जोड़ता है और अलग-अलग प्रोसेसर पर बाइट ऑर्डर (लिटिल-एंडियन बनाम बिग-एंडियन) भिन्न हो सकता है। क्रॉस-प्लेटफॉर्म पोर्टेबिलिटी के लिए पूरे पैडेड स्ट्रक्चर के बजाय फील्ड्स को तय बाइट क्रम में अलग-अलग सीरियलाइज करना बेहतर होता है।

Syntax, Formula & Technical Example (Binary File Operations: fread() and fwrite() in C)

#include <stdio.h>
struct Emp { int id; char name[20]; double pay; };
int main(void) {
    struct Emp out = {101, "Kiran", 48500.5}, in;
    FILE *fp = fopen("emp.dat", "wb");
    if (!fp) return 1;
    fwrite(&out, sizeof(struct Emp), 1, fp);
    fclose(fp);
    fp = fopen("emp.dat", "rb");
    if (fp && fread(&in, sizeof(struct Emp), 1, fp) == 1)
        printf("%d %s %.1f\n", in.id, in.name, in.pay);
    if (fp) fclose(fp);
    return 0;
}

Binary File Operations: fread() and fwrite() in C Quick Reference & Comparison Table

AspectTechnical SpecificationExam Key Point
fwrite() return valuesize_t count of complete elements writtenLess than nmemb signals write error
fread() return valuesize_t count of complete items readZero at EOF; check feof/ferror if < nmemb
Binary mode flag "b"Disables \n <-> \r\n & Ctrl+Z translationMandatory on Windows for raw struct I/O
Pointer field in structSaves RAM address, not pointed stringCauses dangling pointer on later fread()

Binary File Operations: fread() and fwrite() in C Top 20 Bilingual MCQs with Answers

Q1. How many arguments do both fread() and fwrite() accept in standard C?

(मानक C में fread() और fwrite() दोनों कितने आर्गुमेंट्स स्वीकार करते हैं?)

(A) 4 arguments

(B) 3 arguments

(C) 2 arguments

(D) 5 arguments

Correct Answer: (A)

[EN] Both take (void *ptr, size_t size, size_t nmemb, FILE *stream) — exactly 4 arguments.

[HI] दोनों फंक्शन्स (ptr, size, nmemb, stream) के रूप में ठीक 4 आर्गुमेंट्स लेते हैं।

Q2. If fwrite(arr, sizeof(int), 5, fp) succeeds completely (where sizeof(int) is 4), what value does fwrite() return?

(यदि fwrite(arr, sizeof(int), 5, fp) पूरी तरह सफल हो जाए (जहाँ sizeof(int)=4), तो fwrite() क्या लौटाएगा?)

(A) 5

(B) 20

(C) 4

(D) 1

Correct Answer: (A)

[EN] fwrite() returns the number of elements written (nmemb = 5), not the total bytes (20).

[HI] fwrite() कुल बाइट्स (20) के बजाय लिखे गए एलिमेंट्स की संख्या (nmemb = 5) लौटाता है।

Q3. Which fopen() mode should be used to open an existing binary file for both reading and updating without deleting its contents?

(पहले से मौजूद बाइनरी फाइल को बिना डेटा मिटाए पढ़ने और अपडेट करने के लिए किस fopen() मोड का उपयोग करना चाहिए?)

(A) "r"

(B) "rb+"

(C) "wb+"

(D) "ab"

Correct Answer: (B)

[EN] "rb+" (or "r+b") opens an existing file in binary mode for both reading and writing without truncation.

[HI] "rb+" (या "r+b") पहले से मौजूद फाइल को बिना मिटाए बाइनरी मोड में पढ़ने और लिखने के लिए खोलता है।

Q4. Why is storing a struct containing char *title; via fwrite() unsafe for reading in a later program execution?

(char *title; वाले स्ट्रक्चर को fwrite() से सेव करके बाद के प्रोग्राम रन में पढ़ना असुरक्षित क्यों होता है?)

(A) char * pointers are always 0 bytes in structs

(B) fwrite() automatically encrypts pointer values

(C) fwrite() writes the memory address stored in title rather than the actual characters

(D) fwrite() refuses to compile if a struct contains pointers

Correct Answer: (C)

[EN] fwrite() copies only the raw bytes inside the struct, saving a runtime memory address that is invalid when reloaded.

[HI] fwrite() स्ट्रक्चर के अंदर केवल पॉइंटर का मेमोरी एड्रेस लिखता है, वास्तविक स्ट्रिंग नहीं, जो दोबारा लोड करने पर अमान्य हो जाता है।

Q5. What happens on Windows if you write binary data containing byte 0x0A using text mode "w" instead of "wb"?

(Windows पर "wb" के बजाय टेक्स्ट मोड "w" में 0x0A बाइट वाला बाइनरी डेटा लिखने पर क्या होता है?)

(A) 0x0A ('\n') is automatically expanded into two bytes 0x0D 0x0A ('\r\n')

(B) 0x0A is deleted from the file

(C) The compiler throws a syntax error

(D) The file becomes read-only

Correct Answer: (A)

[EN] Text mode on Windows translates '\n' (0x0A) to CR+LF (0x0D 0x0A), corrupting binary structures and offsets.

[HI] Windows पर टेक्स्ट मोड '\n' (0x0A) को '\r\n' (0x0D 0x0A) में बदल देता है, जिससे बाइनरी डेटा और ऑफसेट खराब हो जाते हैं।

Q6. What is the return type of fread() and fwrite() in <stdio.h>?

(<stdio.h> में fread() और fwrite() का रिटर्न टाइप क्या है?)

(A) int

(B) size_t

(C) FILE*

(D) long

Correct Answer: (B)

[EN] Both functions return size_t (an unsigned integer type) representing the count of items transferred.

[HI] दोनों फंक्शन्स size_t (अनसाइन्ड इंटीजर टाइप) लौटाते हैं जो ट्रांसफर किए गए आइटम्स की संख्या बताता है।

Q7. In while (fread(&rec, sizeof(rec), 1, fp) == 1), when does the loop terminate?

(while (fread(&rec, sizeof(rec), 1, fp) == 1) में लूप कब समाप्त होता है?)

(A) Immediately after reading the first record

(B) Only when fclose(fp) is called inside the loop

(C) When fewer than 1 complete record remains (at EOF or read error)

(D) When rec.id equals zero

Correct Answer: (C)

[EN] fread(..., 1, fp) returns 1 for each complete record read and 0 when EOF or an error prevents reading a full record.

[HI] fread(..., 1, fp) प्रत्येक पूर्ण रिकॉर्ड पढ़ने पर 1 और EOF या त्रुटि पर 0 लौटाता है, जिससे लूप रुक जाता है।

Q8. Which two problems can affect raw binary files transferred directly via fwrite() between different CPU architectures?

(अलग-अलग CPU आर्किटेक्चर के बीच सीधे fwrite() से बनाई बाइनरी फाइल्स में कौन-सी दो समस्याएं आ सकती हैं?)

(A) ASCII to EBCDIC newline loops

(B) Syntax errors and missing headers

(C) Struct alignment padding and byte endianness differences

(D) Lack of stdio buffering and integer division

Correct Answer: (C)

[EN] Different compilers/CPUs may pad structs differently and use little-endian vs big-endian byte ordering.

[HI] अलग-अलग कंपाइलर और CPU में स्ट्रक्चर पैडिंग बाइट्स तथा एंडियननेस (लिटिल/बिग) अलग होने से डेटा गलत पढ़ा जा सकता है।

Q9. How many bytes are written by fwrite(buf, 1, 256, fp) if all 256 bytes succeed?

(यदि सभी 256 बाइट्स सफलतापूर्वक लिखे जाएं, तो fwrite(buf, 1, 256, fp) कुल कितने बाइट्स लिखेगा?)

(A) 1 byte

(B) 256 bytes

(C) 512 bytes

(D) 257 bytes

Correct Answer: (B)

[EN] Total bytes transferred equals size * nmemb = 1 * 256 = 256 bytes.

[HI] कुल ट्रांसफर किए गए बाइट्स size * nmemb = 1 * 256 = 256 बाइट्स होते हैं।

Q10. What does the first parameter const void *ptr in fwrite() allow?

(fwrite() में पहला पैरामीटर const void *ptr किस बात की अनुमति देता है?)

(A) Passing a pointer to any data type (int, array, or struct) without explicit casting

(B) Passing the filename string directly

(C) Auto-allocating heap memory

(D) Modifying the input buffer inside fwrite()

Correct Answer: (A)

[EN] const void * accepts any object pointer cleanly while promising that fwrite() will not modify the caller's data.

[HI] const void * किसी भी डेटा टाइप (int, array, struct) का पता बिना कास्ट किए स्वीकार करता है और डेटा में बदलाव न करने की गारंटी देता है।

Q11. If a binary file contains 3 records of 32 bytes each and you call fread(buf, 32, 5, fp), what does fread() return?

(यदि किसी बाइनरी फाइल में 32 बाइट्स के 3 रिकॉर्ड हैं और आप fread(buf, 32, 5, fp) कॉल करते हैं, तो fread() क्या लौटाएगा?)

(A) 96

(B) EOF (-1)

(C) 3

(D) 5

Correct Answer: (C)

[EN] Only 3 complete 32-byte items exist before EOF, so fread() transfers 96 bytes and returns 3.

[HI] EOF से पहले केवल 3 पूर्ण 32-बाइट रिकॉर्ड मौजूद हैं, इसलिए fread() 96 बाइट्स पढ़कर 3 लौटाता है।

Q12. Which mode creates a brand-new empty binary file for both writing and reading, discarding any existing file of the same name?

(कौन-सा मोड समान नाम वाली पुरानी फाइल को मिटाकर लिखने और पढ़ने दोनों के लिए एक नई खाली बाइनरी फाइल बनाता है?)

(A) "rb+"

(B) "ab+"

(C) "wb+"

(D) "rb"

Correct Answer: (C)

[EN] "wb+" (or "w+b") creates or truncates the file to zero length and opens it in binary read/write mode.

[HI] "wb+" (या "w+b") फाइल को खाली करके या नई बनाकर बाइनरी रीड/राइट मोड में खोलता है।

Q13. What happens if you pass size = 0 to fread(ptr, 0, 10, fp)?

(यदि आप fread(ptr, 0, 10, fp) में size = 0 पास करते हैं, तो क्या होता है?)

(A) It reads the entire file

(B) It reads no bytes and returns 0

(C) It returns 10

(D) It causes a division by zero crash

Correct Answer: (B)

[EN] Per the C standard, if either size or nmemb is 0, fread() and fwrite() return 0 and do not change stream state or buffer.

[HI] C मानक के अनुसार यदि size या nmemb शून्य हो, तो fread() और fwrite() कोई डेटा नहीं पढ़ते/लिखते और 0 लौटाते हैं।

Q14. How much file space does storing 1,000 struct Student records take in binary mode compared to formatted text?

(फॉर्मेटेड टेक्स्ट की तुलना में बाइनरी मोड में 1,000 struct Student रिकॉर्ड्स स्टोर करने का क्या प्रमुख लाभ है?)

(A) Files are compressed with ZIP automatically

(B) Every record becomes human-readable in Notepad

(C) Every record has a fixed size (sizeof(struct Student)), enabling O(1) random access

(D) Pointers inside structs get dereferenced automatically

Correct Answer: (C)

[EN] Fixed-size binary records occupy predictable offsets (k * sizeof(struct)), enabling direct seeking with fseek().

[HI] निश्चित आकार के बाइनरी रिकॉर्ड्स का ऑफसेट (k * sizeof(struct)) तय होता है, जिससे fseek() द्वारा तुरंत किसी भी रिकॉर्ड पर जाया जा सकता है।

Q15. After fwrite(&x, sizeof(x), 1, fp) writes to a "wb+" stream, what must you do before immediately calling fread() on the same stream?

("wb+" स्ट्रीम पर fwrite(&x, sizeof(x), 1, fp) करने के तुरंत बाद उसी स्ट्रीम पर fread() कॉल करने से पहले क्या करना जरूरी है?)

(A) Call fopen() again without closing

(B) Call remove() on the file

(C) Call a file positioning function like rewind(fp) or fseek() (or fflush())

(D) Nothing; fread() automatically rewinds to byte 0

Correct Answer: (C)

[EN] First, the position indicator is at the end after writing; second, ANSI C forbids switching directly from output to input without an intervening fflush() or positioning call (fseek/rewind).

[HI] लिखने के बाद पॉइंटर अंत में होता है, और मानक C के अनुसार बिना fflush() या fseek()/rewind() के सीधे राइट से रीड पर स्विच करना अपरिभाषित व्यवहार है।

Q16. Which of the following statements about binary file I/O in C is NOT true?

(C में बाइनरी फाइल I/O के बारे में निम्नलिखित में से कौन-सा कथन सत्य नहीं है?)

(A) "ab" opens a binary file to append data at the end

(B) fread() appends a null terminator '\0' after every read block

(C) fwrite() does not convert numeric types to ASCII digits

(D) Binary files store numbers in raw internal bit representation

Correct Answer: (B)

[EN] fread() copies raw bytes verbatim into memory and never appends '\0' automatically—if you need a C string, you must manage null termination yourself.

[HI] fread() रॉ बाइट्स की नकल करता है और कभी अपने आप '\0' नहीं जोड़ता; C स्ट्रिंग के लिए नल टर्मिनेटर स्वयं संभालना होता है।

Q17. Within Binary File Operations: fread() and fwrite() in C, which aspect directly maps to: "size_t count of complete elements written"?

(Binary File Operations: fread() and fwrite() in C में कौन सा Aspect सीधे "size_t count of complete elements written" से संबंधित है?)

(A) Binary mode flag "b"

(B) fread() return value

(C) fwrite() return value

(D) Pointer field in struct

Correct Answer: (C)

[EN] In Binary File Operations: fread() and fwrite() in C, 'fwrite() return value' handles 'size_t count of complete elements written' (Less than nmemb signals write error).

[HI] Binary File Operations: fread() and fwrite() in C में 'fwrite() return value' का कार्य/विवरण 'size_t count of complete elements written' (Less than nmemb signals write error) है।

Q18. Which option accurately describes 'fread() return value' in Binary File Operations: fread() and fwrite() in C?

(Binary File Operations: fread() and fwrite() in C के संदर्भ में 'fread() return value' की सही विशेषता कौन सी है?)

(A) size_t count of complete elements written

(B) size_t count of complete items read

(C) Disables \n <-> \r\n & Ctrl+Z translation

(D) Saves RAM address, not pointed string

Correct Answer: (B)

[EN] 'fread() return value' provides 'size_t count of complete items read' — key point: Zero at EOF; check feof/ferror if < nmemb.

[HI] 'fread() return value' का मुख्य विवरण 'size_t count of complete items read' है (Zero at EOF; check feof/ferror if < nmemb)।

Q19. In Binary File Operations: fread() and fwrite() in C, identify the correct parameter for the specification: "Disables \n <-> \r\n & Ctrl+Z translation".

(Binary File Operations: fread() and fwrite() in C में "Disables \n <-> \r\n & Ctrl+Z translation" विवरण किस विकल्प के लिए सही है?)

(A) Binary mode flag "b"

(B) Pointer field in struct

(C) fwrite() return value

(D) fread() return value

Correct Answer: (A)

[EN] 'Binary mode flag "b"' corresponds to 'Disables \n <-> \r\n & Ctrl+Z translation' (Mandatory on Windows for raw struct I/O).

[HI] 'Binary mode flag "b"' का संबंध 'Disables \n <-> \r\n & Ctrl+Z translation' (Mandatory on Windows for raw struct I/O) से है।

Q20. Considering Binary File Operations: fread() and fwrite() in C, what key behavior defines 'Pointer field in struct'?

(Binary File Operations: fread() and fwrite() in C में 'Pointer field in struct' की मुख्य भूमिका या मान क्या है?)

(A) Saves RAM address, not pointed string

(B) size_t count of complete items read

(C) Disables \n <-> \r\n & Ctrl+Z translation

(D) size_t count of complete elements written

Correct Answer: (A)

[EN] 'Pointer field in struct' represents 'Saves RAM address, not pointed string' (Causes dangling pointer on later fread()).

[HI] 'Pointer field in struct' का अर्थ/मान 'Saves RAM address, not pointed string' है (Causes dangling pointer on later fread())।

Binary File Operations: fread() and fwrite() in C — Exam FAQs

Q1: Why are binary files unreadable in plain text editors like Notepad?

बाइनरी फाइल्स Notepad जैसे टेक्स्ट एडिटर में अजीब कैरेक्टर्स के रूप में क्यों दिखती हैं?

[EN] Binary files contain raw integer, float, and padding bytes (such as 0x00 or 0xFF) rather than printable ASCII text codes, so editors interpret arbitrary byte patterns as garbled symbols.

[HI] बाइनरी फाइल्स में प्रिंटेबल ASCII टेक्स्ट के बजाय पूर्णांक, फ्लोट और पैडिंग के रॉ बाइट्स (जैसे 0x00 या 0xFF) होते हैं, जिन्हें टेक्स्ट एडिटर अजीब चिन्हों के रूप में दिखाते हैं।

Q2: Is it better to call fread(&arr, sizeof(int), 100, fp) once or in a loop of 100 calls?

100 पूर्णांक पढ़ने के लिए fread(arr, sizeof(int), 100, fp) एक बार कॉल करना बेहतर है या 100 बार लूप चलाना?

[EN] A single call with nmemb = 100 is faster because it incurs one function-call overhead and transfers the contiguous array in a single buffered operation.

[HI] nmemb = 100 के साथ एक ही कॉल करना अधिक तेज होता है क्योंकि इससे फंक्शन-कॉल ओवरहेड घटता है और पूरा सन्निहित ऐरे एक बार में ट्रांसफर हो जाता है।

Q3: Does sizeof(struct) always equal the exact sum of its member sizes?

क्या sizeof(struct) हमेशा उसके सभी मेंबर्स के आकार के योग के बराबर होता है?

[EN] No; compilers often add unused padding bytes between members or at the end of a struct to satisfy CPU memory alignment rules.

[HI] नहीं; CPU मेमोरी अलाइनमेंट नियमों को पूरा करने के लिए कंपाइलर मेंबर्स के बीच या अंत में अतिरिक्त पैडिंग बाइट्स जोड़ सकता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)