Constants and Literals in C: Integer, Real, String, Character Notes in Hindi & English : कांस्टेंट्स और लिटरल्स: संख्यात्मक, फ्लोट और एस्केप सीक्वेन्स और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

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

Overview: Constants and literals represent fixed immutable values in C source code, categorized into Integer (decimal, octal 0, hex 0x), Real/Floating-point, Character ('A' and escape sequences), and String ("text") literals. Named constants are created via typeless #define preprocessor macros, typed read-only const variables, or compile-time integer enum enumerators.

अध्याय सार: C प्रोग्राम में कांस्टेंट्स और लिटरल्स ऐसे अपरिवर्तनीय मान होते हैं जिन्हें रनटाइम पर बदला नहीं जा सकता; इनमें Integer (डेसीमल, ऑक्टल 0, हेक्साडेसीमल 0x), Real/Floating, Character ('A' व एस्केप सीक्वेन्स) और String ("text") लिटरल्स शामिल हैं। नामित कांस्टेंट बनाने के लिए #define मैक्रो, const कीवर्ड अथवा enum का उपयोग किया जाता है।

Constants and Literals in C: Integer, Real, String, Character: Detailed Notes & Architecture (कांस्टेंट्स और लिटरल्स: संख्यात्मक, फ्लोट और एस्केप सीक्वेन्स)

1. Integer Literals: Decimal, Octal (0), Hex (0x) & Suffixes (इंटीजर लिटरल्स: डेसीमल, ऑक्टल (0), हेक्स (0x) और सफिक्स)

[EN] C supports three classic integer literal radices (plus binary 0b standardized in C23): Decimal starts with digits 1-9 (e.g., 75), Octal starts with leading zero 0 followed exclusively by digits 0-7 (e.g., 075 = 61 in decimal; trap: 08 or 019 fails compilation!), and Hexadecimal begins with 0x or 0X using 0-9 and A-F (e.g., 0x4B = 75). Integer suffixes dictate type explicitly: U/u for unsigned, L/l for long, and LL/ll for long long (e.g., 50000UL). Commas, spaces, and currency signs (like 1,000) are strictly forbidden inside numeric literals.

[HI] C में पूर्णांक लिटरल्स तीन मुख्य आधारों में लिखे जा सकते हैं (तथा C23 में बाइनरी 0b): डेसीमल (75), ऑक्टल जो शून्य '0' से शुरू होकर केवल 0-7 अंक लेता है (जैसे 075 = डेसीमल 61; 08 लिखना कंपाइल त्रुटि है!), और हेक्साडेसीमल जो 0x/0X से शुरू होता है (0x4B = 75)। अंत में U (unsigned), L (long) या LL (long long) सफिक्स लगाए जा सकते हैं; संख्या में कॉमा (1,000) लगाना अमान्य है।

2. Floating-Point (Real) Literals & Scientific Notation (फ्लोटिंग-पॉइंट (Real) लिटरल्स और वैज्ञानिक संकेतन)

[EN] Real literals take either fractional decimal form (3.14, .25, 7.0) requiring a decimal point, or exponential scientific notation (6.02e23, 1.5E-4 representing 1.5 * 10^-4) where both mantissa and integer exponent must contain digits. Every unsuffixed floating constant has type double; appending f/F narrows it to float (3.14f) and l/L promotes it to long double (3.14L). C99 also introduced hexadecimal floating constants such as 0x1.8p3 (1.5 * 2^3 = 12.0), where 'p' denotes binary power of 2.

[HI] रियल लिटरल्स या तो दशमलव रूप (3.14, .25) में होते हैं या वैज्ञानिक घातांक रूप (1.5e-4 अर्थात 1.5 * 10^-4) में। बिना सफिक्स वाले प्रत्येक दशमलव लिटरल का टाइप double होता है; अंत में f लगाने से वह float तथा L लगाने से long double बनता है। C99 में 0x1.8p3 जैसे हेक्साडेसीमल फ्लोट लिटरल भी जोड़े गए जहाँ p, 2 की घात को दर्शाता है।

3. Character Constants, Escape Sequences & String Literals (कैरेक्टर कांस्टेंट्स, एस्केप सीक्वेन्स और स्ट्रिंग लिटरल्स)

[EN] Single-quoted Character Constants ('A', '9') hold one character—and notably have type 'int' in C (so sizeof('A') == sizeof(int) == 4, unlike C++ where sizeof('A') == 1!). Special non-printable characters use backslash Escape Sequences: '\n' (newline), '\t' (horizontal tab), '\0' (null terminator ASCII 0), '\\' (backslash), '\'' (single quote), '\"' (double quote), '\r' (carriage return), '\b' (backspace), '\a' (bell), plus octal '\101' and hex '\x41' ('A'). Double-quoted String Literals ("Hi") store characters sequentially followed by an automatic '\0' byte (so sizeof("A") == 2) and live in read-only memory where mutating them via char *p = "Hi"; p[0] = 'h'; triggers Undefined Behavior.

[HI] सिंगल कोट्स में लिखे कैरेक्टर कांस्टेंट ('A') का टाइप C में 'int' होता है, इसलिए C में sizeof('A') = 4 (sizeof(int)) आता है जबकि C++ में 1! नॉन-प्रिंटेबल अक्षरों के लिए '\n' (नई लाइन), '\t' (टैब), '\0' (नल कैरेक्टर), '\\' (बैकस्लैश), '\r' व हेक्स '\x41' जैसे एस्केप सीक्वेन्स उपयोग होते हैं। डबल कोट्स में लिखी स्ट्रिंग ("A") के अंत में स्वतः '\0' जुड़ने से sizeof("A") = 2 होता है; स्ट्रिंग लिटरल में सीधा बदलाव करना अपरिभाषित व्यवहार (UB) है।

4. Symbolic Constants: #define vs const vs enum (सिम्बॉलिक कांस्टेंट्स: #define बनाम const बनाम enum)

[EN] #define PI 3.14159 instructs the preprocessor to perform raw textual substitution before compilation—it consumes zero variable RAM, lacks data type checking, and obeys no block scope until #undef. Conversely, 'const double PI = 3.14159;' creates a type-checked, scoped read-only variable enforced by the compiler (whose address &PI is valid). Importantly, in C (unlike C++), a 'const int N = 10;' is a read-only variable rather than an Integer Constant Expression, so 'int arr[N];' at file scope fails in C89/C99! When true compile-time integer constants with zero RAM cost are needed inside switch cases or global array sizes, use enum { MAX = 100 };.

[HI] #define एक टाइपलेस प्रीप्रोसेसर टेक्स्ट प्रतिस्थापन है जो कोई वेरिएबल मेमोरी नहीं लेता, जबकि 'const' कंपाइलर द्वारा टाइप-जांचा गया स्कोप्ड रीड-ओनली वेरिएबल बनाता है। ध्यान देने योग्य है कि C में (C++ के विपरीत) 'const int N = 10;' कंपाइल-टाइम कांस्टेंट एक्सप्रेशन नहीं माना जाता, इसलिए ग्लोबल एरे का आकार देने या switch case में enum { MAX = 100 }; या #define का उपयोग किया जाता है।

Syntax, Formula & Technical Example (Constants and Literals in C: Integer, Real, String, Character)

#include <stdio.h>
#define LIMIT 100                 /* Typeless preprocessor macro */

int main(void) {
    int dec = 25, oct = 025, hex = 0x25; /* 25, 21 (2*8+5), 37 (2*16+5) */
    const double PI = 3.14159;           /* Type-checked read-only variable */
    printf("dec=%d oct=%d hex=%d PI=%.2f\n", dec, oct, hex, PI);
    printf("sizeof('A')=%zu sizeof(\"A\")=%zu\n", sizeof('A'), sizeof("A"));
    return 0;                            /* Output: sizeof('A')=4 sizeof("A")=2 */
}

Constants and Literals in C: Integer, Real, String, Character Quick Reference & Comparison Table

Constant / Literal KindSyntax & Representation RuleType & Exam Fact
Integer LiteralsDecimal (75), Octal (075 = 61), Hex (0x4B = 75)08 is syntax error; U/L/LL suffixes fix type
Floating Literals3.14 (double), 3.14f (float), 1.5e-4 (scientific)Default type is double; commas/spaces illegal
Character & Escapes'A' (int type), '\n', '\t', '\0', '\x41'In C, sizeof('A') == sizeof(int) (usually 4B)
String & Symbolic"ABC" (4B with '\0'), #define vs constMutating string literal is UB; const is read-only var

Constants and Literals in C: Integer, Real, String, Character Top 20 Bilingual MCQs with Answers

Q1. What decimal value is stored in x by the declaration: int x = 025;

(घोषणा 'int x = 025;' द्वारा वेरिएबल x में कौन सा डेसीमल मान संग्रहीत होगा?)

(A) 21

(B) 37

(C) 25

(D) 17

Correct Answer: (A)

[EN] A leading zero marks 025 as an Octal (base-8) literal: 2 * 8^1 + 5 * 8^0 = 16 + 5 = 21.

[HI] शुरुआती शून्य (0) होने से 025 एक ऑक्टल संख्या मानी जाती है: (2 * 8) + 5 = 21।

Q2. Why does the statement 'int val = 018;' fail to compile in C?

(C में कथन 'int val = 018;' कंपाइल होने में विफल क्यों हो जाता है?)

(A) Leading zeros are forbidden for all integer constants

(B) 018 is treated as a character constant missing quotes

(C) 18 exceeds the maximum range of int

(D) Leading 0 makes 018 an octal literal, and digit '8' is invalid in base-8 (only 0-7 allowed)

Correct Answer: (D)

[EN] Any integer literal starting with 0 (without 0x/0b) must contain solely octal digits 0 through 7.

[HI] 0 से शुरू होने के कारण यह ऑक्टल लिटरल है और ऑक्टल में केवल 0 से 7 अंक ही मान्य हैं, '8' अवैध है।

Q3. On a standard 32/64-bit compiler (where sizeof(int) == 4), what does printf("%zu %zu", sizeof('A'), sizeof("A")); output in C?

(सामान्य 32/64-बिट C कंपाइलर पर printf("%zu %zu", sizeof('A'), sizeof("A")); का आउटपुट क्या होगा?)

(A) 4 2

(B) 4 1

(C) 1 2

(D) 1 1

Correct Answer: (A)

[EN] In C (unlike C++!), character constants like 'A' have type int (4 bytes), while string literal "A" is char[2] ('A' + '\0') = 2 bytes.

[HI] C में कैरेक्टर लिटरल 'A' का प्रकार int (4 बाइट) होता है, जबकि स्ट्रिंग "A" में 'A' व '\0' होने से 2 बाइट लगते हैं।

Q4. Which escape sequence represents the Null character used to terminate C strings (ASCII 0)?

(C स्ट्रिंग्स को समाप्त करने वाले Null कैरेक्टर (ASCII 0) को कौन सा एस्केप सीक्वेन्स दर्शाता है?)

(A) \a

(B) \0

(C) \t

(D) \n

Correct Answer: (B)

[EN] '\0' has integer value 0 and marks the end of every null-terminated C character string.

[HI] '\0' (बैकस्लैश शून्य) ASCII मान 0 वाला नल टर्मिनेटर है जो हर C स्ट्रिंग के अंत को दर्शाता है।

Q5. What ASCII character does the hexadecimal escape sequence '\x41' produce?

(हेक्साडेसीमल एस्केप सीक्वेन्स '\x41' किस ASCII कैरेक्टर को दर्शाता है?)

(A) 'A' (decimal 65)

(B) 'a' (decimal 97)

(C) '1' (decimal 49)

(D) '0' (decimal 48)

Correct Answer: (A)

[EN] 0x41 = 4 * 16 + 1 = 65 in decimal, which is the ASCII code for uppercase 'A'.

[HI] हेक्स 0x41 का डेसीमल मान 4*16 + 1 = 65 होता है, जो ASCII में बड़े अक्षर 'A' का कोड है।

Q6. How many bytes does the string literal "Computer" occupy in memory?

(स्ट्रिंग लिटरल "Computer" मेमोरी में कुल कितने बाइट्स स्थान घेरता है?)

(A) 7 bytes

(B) 9 bytes (8 characters + implicit '\0')

(C) 10 bytes

(D) 8 bytes

Correct Answer: (B)

[EN] C automatically appends a trailing null byte '\0' to every string literal, giving strlen("Computer") + 1 = 8 + 1 = 9 bytes.

[HI] "Computer" में 8 अक्षरों के साथ अंत में स्वतः जुड़ने वाला 1 नल बाइट '\0' मिलाकर कुल 9 बाइट्स लगते हैं।

Q7. What happens at runtime if you execute: char *s = "Hello"; s[0] = 'J';

(यदि आप 'char *s = "Hello"; s[0] = 'J';' कोड चलाते हैं, तो रनटाइम पर क्या होगा?)

(A) Undefined Behavior (typically a Segmentation Fault / crash because string literals sit in read-only memory)

(B) s neatly changes to "Jello"

(C) Only the '\0' terminator changes

(D) Compile-time warning only, safely updates RAM

Correct Answer: (A)

[EN] To modify a string safely, copy it into a writable array: char s[] = "Hello"; s[0] = 'J';.

[HI] स्ट्रिंग लिटरल प्रायः रीड-ओनली मेमोरी (.rodata) में रहते हैं, इसलिए पॉइंटर से उनमें बदलाव करने पर सेगमेंटेशन फॉल्ट (UB) आ सकता है।

Q8. Which suffix turns a decimal floating-point literal into a 4-byte 'float' instead of the default 8-byte 'double'?

(कौन सा सफिक्स किसी दशमलव लिटरल को डिफ़ॉल्ट 8-बाइट 'double' के बजाय 4-बाइट 'float' बनाता है?)

(A) u or U

(B) l or L

(C) f or F (e.g., 3.14f)

(D) d or D

Correct Answer: (C)

[EN] Appending f/F yields type float, no suffix yields double, and appending l/L yields long double.

[HI] अंत में f या F लगाने से लिटरल float बनता है, बिना सफिक्स के double तथा L लगाने से long double बनता है।

Q9. What decimal value does the scientific-notation literal '2.5e3' represent?

(वैज्ञानिक संकेतन लिटरल '2.5e3' किस दशमलव मान को दर्शाता है?)

(A) 7.5

(B) 2500.0 (double)

(C) 250.0

(D) 0.0025

Correct Answer: (B)

[EN] 2.5e3 equals 2.5 * 10^3 = 2500.0 and carries type double.

[HI] 2.5e3 का अर्थ 2.5 * 10^3 = 2500.0 (double टाइप) होता है।

Q10. What is a major difference between '#define MAX 100' and 'const int MAX = 100;' in C?

(C में '#define MAX 100' और 'const int MAX = 100;' के बीच एक प्रमुख अंतर क्या है?)

(A) #define is a typeless preprocessor macro substitution, whereas const creates a typed scoped read-only variable

(B) const macros must start with #

(C) #define can be changed at runtime while const cannot

(D) const uses zero memory while #define allocates heap memory

Correct Answer: (A)

[EN] You can take the address &MAX of a const variable and restrict it to block scope, whereas #define is pure text substitution.

[HI] #define प्रीप्रोसेसर टेक्स्ट प्रतिस्थापन है जिसका कोई टाइप या स्कोप नहीं होता, जबकि const एक टाइप-युक्त स्कोप्ड वेरिएबल बनाता है।

Q11. In ANSI C89, why does writing 'const int SIZE = 5; int arr[SIZE];' at global (file) scope fail to compile?

(ANSI C89 में ग्लोबल स्कोप पर 'const int SIZE = 5; int arr[SIZE];' लिखने पर कंपाइल त्रुटि क्यों आती है?)

(A) const variables always default to 0

(B) Arrays in C can only hold float values

(C) In C, a const variable is 'read-only', NOT a compile-time constant expression required for static global array bounds

(D) Global arrays cannot have size 5

Correct Answer: (C)

[EN] Unlike C++, C requires an Integer Constant Expression (#define or enum) for global array bounds and switch case labels.

[HI] C में const केवल रीड-ओनली वेरिएबल होता है, कंपाइल-टाइम स्थिरांक नहीं; इसलिए ग्लोबल एरे के आकार हेतु #define या enum चाहिए।

Q12. Which escape sequence moves the cursor back to the beginning of the CURRENT line without advancing to the next line?

(कौन सा एस्केप सीक्वेन्स कर्सर को अगली लाइन पर ले जाए बिना वर्तमान लाइन की शुरुआत में वापस ले जाता है?)

(A) \v (Vertical Tab)

(B) \r (Carriage Return)

(C) \f (Form Feed)

(D) \n (Newline)

Correct Answer: (B)

[EN] \r returns the print head/cursor to column 0 of the same line, allowing progress bars to overwrite text in place.

[HI] \r (Carriage Return) कर्सर को उसी लाइन के आरंभ में लाता है, जबकि \n अगली नई लाइन पर ले जाता है।

Q13. What is the type and decimal value of the literal '0x1A'?

(लिटरल '0x1A' का प्रकार और डेसीमल मान क्या है?)

(A) int with value 26

(B) int with value 16

(C) hex char with value 110

(D) double with value 1.10

Correct Answer: (A)

[EN] Prefix 0x denotes hexadecimal (base 16): (1 * 16) + 10 (A) = 26.

[HI] 0x हेक्साडेसीमल दर्शाता है जहाँ A = 10 होता है, इसलिए (1 * 16) + 10 = 26 (int) प्राप्त होगा।

Q14. Which of the following is an INVALID numeric literal in standard C89/C99/C11?

(मानक C89/C99/C11 में निम्नलिखित में से कौन सा संख्यात्मक लिटरल अमान्य (Invalid) है?)

(A) 0xFFu

(B) 1,00,000

(C) 1e-5

(D) 0.5f

Correct Answer: (B)

[EN] Numeric constants cannot contain commas, dollar signs, or spaces; only optional suffixes and base prefixes are allowed.

[HI] संख्यात्मक लिटरल्स में कॉमा (,) या स्पेस का प्रयोग पूरी तरह अमान्य है।

Q15. In C, how do you safely write a single literal backslash inside a string like C:\docs?

(C में स्ट्रिंग के भीतर एक वास्तविक बैकस्लैश (जैसे C:\docs) लिखने का सही तरीका क्या है?)

(A) "C:/\docs"

(B) "C:\d"

(C) "C:\\docs"

(D) "C:\docs"

Correct Answer: (C)

[EN] Because \ begins an escape sequence, two backslashes (\\) are required to represent one literal backslash.

[HI] चूँकि सिंगल \ एस्केप सीक्वेन्स शुरू करता है, इसलिए एक वास्तविक बैकस्लैश प्रिंट करने हेतु दो बार \\ लिखना होता है।

Q16. Which statement about Constants and Literals in C is FALSE?

(C में कांस्टेंट्स और लिटरल्स के संदर्भ में निम्नलिखित में से कौन सा कथन असत्य (FALSE) है?)

(A) Unsuffixed floating constants like 4.5 default to double

(B) Octal constants begin with a leading zero (0) and allow digits 0-7

(C) 'A' and "A" have identical data types and occupy the exact same number of bytes in C

(D) An enum enumerator acts as a true compile-time int constant

Correct Answer: (C)

[EN] 'A' is a character constant of type int (usually 4 bytes), whereas "A" is a 2-byte char array containing 'A' and '\0'.

[HI] 'A' एक कैरेक्टर कांस्टेंट (int टाइप, प्रायः 4 बाइट) है जबकि "A" 2 बाइट की स्ट्रिंग ('A' + '\0') है—दोनों बिल्कुल भिन्न हैं।

Q17. Within Constants and Literals in C: Integer, Real, String, Character, which constant / literal kind directly maps to: "Decimal (75), Octal (075 = 61), Hex (0x4B = 75)"?

(Constants and Literals in C: Integer, Real, String, Character में कौन सा Constant / Literal Kind सीधे "Decimal (75), Octal (075 = 61), Hex (0x4B = 75)" से संबंधित है?)

(A) Character & Escapes

(B) String & Symbolic

(C) Floating Literals

(D) Integer Literals

Correct Answer: (D)

[EN] In Constants and Literals in C: Integer, Real, String, Character, 'Integer Literals' handles 'Decimal (75), Octal (075 = 61), Hex (0x4B = 75)' (08 is syntax error; U/L/LL suffixes fix type).

[HI] Constants and Literals in C: Integer, Real, String, Character में 'Integer Literals' का कार्य/विवरण 'Decimal (75), Octal (075 = 61), Hex (0x4B = 75)' (08 is syntax error; U/L/LL suffixes fix type) है।

Q18. Which option accurately describes 'Floating Literals' in Constants and Literals in C: Integer, Real, String, Character?

(Constants and Literals in C: Integer, Real, String, Character के संदर्भ में 'Floating Literals' की सही विशेषता कौन सी है?)

(A) "ABC" (4B with '\0'), #define vs const

(B) Decimal (75), Octal (075 = 61), Hex (0x4B = 75)

(C) 3.14 (double), 3.14f (float), 1.5e-4 (scientific)

(D) 'A' (int type), '\n', '\t', '\0', '\x41'

Correct Answer: (C)

[EN] 'Floating Literals' provides '3.14 (double), 3.14f (float), 1.5e-4 (scientific)' — key point: Default type is double; commas/spaces illegal.

[HI] 'Floating Literals' का मुख्य विवरण '3.14 (double), 3.14f (float), 1.5e-4 (scientific)' है (Default type is double; commas/spaces illegal)।

Q19. In Constants and Literals in C: Integer, Real, String, Character, identify the correct parameter for the specification: "'A' (int type), '\n', '\t', '\0', '\x41'".

(Constants and Literals in C: Integer, Real, String, Character में "'A' (int type), '\n', '\t', '\0', '\x41'" विवरण किस विकल्प के लिए सही है?)

(A) String & Symbolic

(B) Character & Escapes

(C) Floating Literals

(D) Integer Literals

Correct Answer: (B)

[EN] 'Character & Escapes' corresponds to ''A' (int type), '\n', '\t', '\0', '\x41'' (In C, sizeof('A') == sizeof(int) (usually 4B)).

[HI] 'Character & Escapes' का संबंध ''A' (int type), '\n', '\t', '\0', '\x41'' (In C, sizeof('A') == sizeof(int) (usually 4B)) से है।

Q20. Considering Constants and Literals in C: Integer, Real, String, Character, what key behavior defines 'String & Symbolic'?

(Constants and Literals in C: Integer, Real, String, Character में 'String & Symbolic' की मुख्य भूमिका या मान क्या है?)

(A) "ABC" (4B with '\0'), #define vs const

(B) 'A' (int type), '\n', '\t', '\0', '\x41'

(C) Decimal (75), Octal (075 = 61), Hex (0x4B = 75)

(D) 3.14 (double), 3.14f (float), 1.5e-4 (scientific)

Correct Answer: (A)

[EN] 'String & Symbolic' represents '"ABC" (4B with '\0'), #define vs const' (Mutating string literal is UB; const is read-only var).

[HI] 'String & Symbolic' का अर्थ/मान '"ABC" (4B with '\0'), #define vs const' है (Mutating string literal is UB; const is read-only var)।

Constants and Literals in C: Integer, Real, String, Character — Exam FAQs

Q1: Why is sizeof('A') equal to 4 in C, whereas in C++ it is equal to 1?

C में sizeof('A') का मान 4 क्यों आता है, जबकि C++ में 1 आता है?

[EN] By C's historical design (from B/PDP-11), character constants like 'A' have type int, so sizeof('A') == sizeof(int) (typically 4). C++ changed character literals to type char (1 byte) to support function overloading like print('A') vs print(65).

[HI] C में 'A' जैसे कैरेक्टर लिटरल का डेटा टाइप int माना गया है, अतः sizeof('A') = sizeof(int) (4 बाइट) आता है; जबकि C++ ने फंक्शन ओवरलोडिंग के लिए इसे char (1 बाइट) कर दिया।

Q2: When should I prefer 'const' over '#define', and when is '#define' or 'enum' required?

हमें कब '#define' के बजाय 'const' चुनना चाहिए, और कब '#define' या 'enum' आवश्यक होता है?

[EN] Use 'const' for typed variables where scoping, debugger visibility, or address-taking helps. Use '#define' or 'enum' when you need a true compile-time constant expression in C (such as switch case labels, bit-field widths, or non-VLA global array sizes).

[HI] जहाँ टाइप सुरक्षा और स्कोप चाहिए वहाँ 'const' बेहतर है; पर C में switch-case लेबल या ग्लोबल एरे का आकार तय करने के लिए '#define' अथवा 'enum' आवश्यक होता है।

Q3: Why does C treat char s[] = "Hi"; differently from char *s = "Hi";?

C में 'char s[] = "Hi";' और 'char *s = "Hi";' के व्यवहार में क्या अंतर है?

[EN] char s[] = "Hi"; allocates a writable 3-byte array on the stack initialized with 'H','i','\0' (modifiable safely). char *s = "Hi"; points directly at a read-only string literal in static memory, where attempting s[0] = 'B' invokes Undefined Behavior.

[HI] char s[] = "Hi"; स्टैक पर 3-बाइट का परिवर्तनीय एरे बनाता है जिसे बदला जा सकता है, जबकि char *s = "Hi"; रीड-ओनली मेमोरी की तरफ पॉइंट करता है जहाँ बदलाव करना क्रैश (UB) कर सकता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)