पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
Enum टाइप्स किसके द्वारा प्रोसेस किए जाते हैं?
enum types are processed by _________
Aसंकलक (Compiler)Compiler
Bपूर्वप्रक्रमक (Preprocessor)Preprocessor
CलिंकरLinker
Dअसेम्बलरAssembler
सही उत्तर / Answer: (A)
हल / Solution
enum भाषा का अपना निर्माण है, इसलिए उसे संकलक (compiler) ही पढ़ता है और हर नाम को उसका मान देता है। पूर्वप्रक्रमक (preprocessor) सिर्फ़ #define और #include जैसे निर्देश सँभालता है और वह न प्रकार समझता है, न क्षेत्र (scope) — यही #define और enum के बीच का बड़ा भेद है। लिंकर अलग-अलग object फ़ाइलें जोड़ता है और असेम्बलर असेम्बली को मशीन कोड बनाता है। इसलिए उत्तर संकलक है।
An enum is a construct of the language itself, so it is the compiler that reads it and ties each name to its value. The preprocessor only handles directives such as #define and #include, and it understands neither types nor scope, which is the main difference between #define and enum. The linker joins separate object files together and the assembler turns assembly into machine code, so neither of them is involved here.
प्रश्न 2उत्तर + हल
Enum में वेरिएबल्स का क्रम क्या होता है?
What is the order of variables in Enum?
Aआरोही क्रमAscending order
Bअवरोही क्रमDescending order
Cरैंडम क्रमRandom order
Dorder() मेथड पर निर्भर करता हैDepends on the order() method
सही उत्तर / Answer: (A)
हल / Solution
enum में पहले नाम को शून्य मिलता है और उसके आगे हर नाम का मान एक-एक बढ़ता जाता है, जब तक आप ख़ुद कोई मान न दें। जैसे enum day {MON, TUE, WED}; में क्रमशः शून्य, एक और दो मिलते हैं। यानी मान आरोही क्रम में चलते हैं। घटते या अनियमित क्रम में वे कभी नहीं बँटते। C में order() नाम का कोई मेथड भी नहीं है, वह दूसरी भाषाओं की बात है। सो उत्तर आरोही क्रम है।
In an enum the first name gets zero and every name after it is one more than the previous one, unless you supply a value yourself. For example enum day {MON, TUE, WED}; gives zero, one and two in that order. The values therefore run in ascending order. They are never handed out in descending or random order, and C has no order() method at all, since that idea belongs to other languages.
प्रश्न 3उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include<stdio.h>
enum FliQi
{
a=1,b
};
enum FliQi1
{
c,d
};
int main()
{
enum FliQi1 s1=c;
enum FliQi1 s=a;
enum FliQi s2=d;
printf("%d",s);
printf("%d",s1);
printf("%d",s2);
}
What will be the output of the following C code?
#include<stdio.h>
enum FliQi
{
a=1,b
};
enum FliQi1
{
c,d
};
int main()
{
enum FliQi1 s1=c;
enum FliQi1 s=a;
enum FliQi s2=d;
printf("%d",s);
printf("%d",s1);
printf("%d",s2);
}
AएररError
B011
C110
D101
सही उत्तर / Answer: (D)
हल / Solution
पहले enum में a को एक दिया है, सो b दो हो जाता है। दूसरे enum में कोई मान नहीं दिया, इसलिए c शून्य और d एक बनता है। अब s में a यानी एक, s1 में c यानी शून्य, और s2 में d यानी एक रखा गया। तीनों printf क्रम से यही मान छापते हैं, सो बिना जगह के 101 बनता है। enum के नाम पूर्णांक ही हैं, इसलिए आपस में बदले जा सकते हैं और एरर नहीं आती।
The first enum sets a to one, which makes b equal to two. The second enum gives no values, so c becomes zero and d becomes one. Now s holds a, that is one; s1 holds c, that is zero; and s2 holds d, that is one. The three printf calls print these values in that order, giving 101 with no spaces. The enum names are plain integers, so mixing them causes no error.
प्रश्न 4उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include<stdio.h>
enum FliQi
{
a,b,c=5
};
int main()
{
enum FliQi s;
b=10;
printf("%d",b);
}
What will be the output of the following C code?
#include<stdio.h>
enum FliQi
{
a,b,c=5
};
int main()
{
enum FliQi s;
b=10;
printf("%d",b);
}
AएररError
B10
C1
D4
सही उत्तर / Answer: (A)
हल / Solution
enum में लिखे नाम स्थिरांक (constants) होते हैं, चर नहीं। यहाँ b का मान एक है और उसे केवल पढ़ा जा सकता है। कोड उसमें दस रखने की कोशिश करता है, पर स्थिरांक निर्धारण के बाईं ओर नहीं आ सकता, क्योंकि उसका अपना कोई भंडारण ही नहीं होता। इसलिए compiler «lvalue required» जैसी त्रुटि देता है और प्रोग्राम बनता ही नहीं। सो दस या एक छपने का सवाल नहीं; उत्तर एरर है।
The names written inside an enum are constants, not variables. Here b has the value one and it can only be read. The code tries to assign ten to it, but a constant cannot stand on the left of an assignment, because it has no storage of its own. The compiler therefore reports an lvalue required error and the program never builds, so neither ten nor one is ever printed.
प्रश्न 5उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include<stdio.h>
enum FliQi
{
a=1,b,c,d,e
};
int main()
{
printf("%d",b*c+e-d);
}
What will be the output of the following C code?
#include<stdio.h>
enum FliQi
{
a=1,b,c,d,e
};
int main()
{
printf("%d",b*c+e-d);
}
Aत्रुटि (Error)Error
B7
C2
D4
सही उत्तर / Answer: (B)
हल / Solution
enum FliQi में a=1 दिया है, इसलिए b=2, c=3, d=4 और e=5 होंगे। अब b*c+e-d को हल कीजिए। पहले गुणा होता है: 2*3 = 6। फिर बाएँ से दाएँ जोड़-घटाव: 6+5 = 11 और 11-4 = 7। इसलिए 7 छपता है। enum स्थिरांकों पर गणित करना पूरी तरह मान्य है, इसलिए त्रुटि नहीं है। 2 सिर्फ़ b का मान है और 4 सिर्फ़ d का।
In enum FliQi, a is set to 1, so b=2, c=3, d=4 and e=5. Now solve b*c+e-d. Multiplication comes first: 2*3 = 6. Then addition and subtraction go left to right: 6+5 = 11 and 11-4 = 7. So 7 is printed. Doing arithmetic on enum constants is fully valid, so there is no error. The value 2 is only b and 4 is only d.
प्रश्न 6उत्तर + हल
यदि इनपुट 2 दिया जाए तो निम्नलिखित C कोड का आउटपुट क्या होगा? #include<stdio.h> enum day { a,b,c=5,d,e }; main() { printf("Enter the value for a"); scanf("%d",a); printf("%d",a); }
What will be the output of the following C code if the input given is 2? #include<stdio.h> enum day { a,b,c=5,d,e }; main() { printf("Enter the value for a"); scanf("%d",a); printf("%d",a); }
A2
B0
C3
DError
सही उत्तर / Answer: (D)
हल / Solution
यहाँ a कोई चर नहीं, enum का स्थिरांक है जिसका मान शून्य है। scanf को किसी object का पता चाहिए, पर यहाँ पते की जगह वही मान शून्य भेजा गया है। इसलिए कोड लिखे रूप में चलता ही नहीं: नए कंपाइलर बिना प्रकार लिखे main() पर रुक जाते हैं, और संकलित हो जाए तो पते शून्य पर लिखते ही कार्यक्रम टूट जाता है। सो 2, 0 या 3 में कोई नहीं छपता और उत्तर Error ठहरता है।
Here a is an enumeration constant whose value is zero, not a variable. scanf needs the address of an object, but the value zero has been passed in place of a pointer. So the code never runs as written: modern compilers stop at the implicit int main(), and even if it compiles, writing to address zero crashes the program. Hence 2, 0 and 3 are all impossible, and the correct choice is Error.
प्रश्न 7उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
enum example {a = 1, b, c};
enum example example1 = 2;
enum example answer()
{
return example1;
}
int main()
{
(answer() == a)? printf("yes"): printf("no");
return 0;
}
What will be the output of the following C code?
#include <stdio.h>
enum example {a = 1, b, c};
enum example example1 = 2;
enum example answer()
{
return example1;
}
int main()
{
(answer() == a)? printf("yes"): printf("no");
return 0;
}
Ayes
Bno
C2
Dत्रुटि (error)error
सही उत्तर / Answer: (B)
हल / Solution
enum example में a=1, b=2 और c=3 हैं। global variable example1 को 2 दिया गया है। C में enum variable को पूर्णांक देना मान्य है, इसलिए कोई त्रुटि नहीं। answer() फ़ंक्शन example1 यानी 2 लौटाता है। शर्त answer() == a का मतलब 2 == 1 है, जो झूठ है। इसलिए ternary ऑपरेटर का दूसरा भाग चलता है और "no" छपता है। 2 तो सिर्फ़ लौटाया गया मान है, वह छपता नहीं।
In enum example, a=1, b=2 and c=3. The global variable example1 is given 2. In C, assigning an integer to an enum variable is allowed, so there is no error. The function answer() returns example1, which is 2. The condition answer() == a means 2 == 1, which is false. So the second part of the ternary operator runs and "no" is printed. The value 2 is only returned, never printed.
प्रश्न 8उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include<stdio.h>
enum FliQi
{
a,b,c=5
};
enum FliQi s;
main()
{
c++;
printf("%d",c);
}
What will be the output of the following C code?
#include<stdio.h>
enum FliQi
{
a,b,c=5
};
enum FliQi s;
main()
{
c++;
printf("%d",c);
}
Aत्रुटि (Error)Error
B5
C6
D2
सही उत्तर / Answer: (A)
हल / Solution
enum FliQi में c=5 एक स्थिरांक है, variable नहीं। c++ का मतलब है c का मान 1 बढ़ाकर वापस c में रखना। स्थिरांक में कुछ लिखा नहीं जा सकता, इसलिए कंपाइलर "expression is not assignable" जैसी त्रुटि देता है। 6 तभी छपता जब c साधारण variable होता। 5, c का असली मान है, पर प्रोग्राम compile नहीं होता। 2 तो c का वह मान है जो c=5 न देने पर होता।
In enum FliQi, c=5 is a constant, not a variable. The expression c++ means add 1 to c and store it back in c. Nothing can be stored in a constant, so the compiler reports an error such as "expression is not assignable". The value 6 would print only if c were an ordinary variable. 5 is the real value of c, but the program never compiles. 2 is what c would be without c=5.
प्रश्न 9उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include<stdio.h>
enum hi{a,b,c};
enum hello{c,d,e};
main()
{
enum hi h;
h=b;
printf("%d",h);
return 0;
}
What will be the output of the following C code?
#include<stdio.h>
enum hi{a,b,c};
enum hello{c,d,e};
main()
{
enum hi h;
h=b;
printf("%d",h);
return 0;
}
A2
B1
Cत्रुटि (Error)Error
D0
सही उत्तर / Answer: (C)
हल / Solution
enum के नाम उस पूरे scope में साधारण पहचान (identifier) की तरह रहते हैं। enum hi में c नाम पहले से है। फिर enum hello में दोबारा c लिखा गया है। एक ही scope में एक नाम दो बार नहीं बनाया जा सकता, इसलिए कंपाइलर "redefinition of enumerator c" की त्रुटि देता है। h=b मान्य है और b=1 है, पर प्रोग्राम compile ही नहीं होता, इसलिए 1 नहीं छपेगा। 2 और 0 भी इसी वजह से ग़लत हैं।
Enum names live in the whole scope as ordinary identifiers. enum hi already has a name c, and enum hello declares c again. The same name cannot be defined twice in one scope, so the compiler gives a "redefinition of enumerator c" error. The line h=b is valid and b is 1, but the program never compiles, so 1 is not printed. The options 2 and 0 are wrong for the same reason.
प्रश्न 10उत्तर + हल
निम्नलिखित सी कोड का आउटपुट क्या होगा? #include<stdio.h> enum class { a,b,c }; enum class m; int main() { printf("%d",sizeof(m)); }
What will be the output of the following C code? #include<stdio.h> enum class { a,b,c }; enum class m; int main() { printf("%d",sizeof(m)); }
A3
Bएक पूर्णांक के आकार के समानSame as the size of an integer
Cएक पूर्णांक के आकार का तीन गुना3 times the size of an integer
Dत्रुटिError
सही उत्तर / Answer: (B)
हल / Solution
enum एक पूर्णांक प्रकार है, और उसकी सूची में कितने नाम हैं इससे चर का आकार नहीं बदलता। compiler enum के चर को int जितनी जगह देता है, सो sizeof(m) वही निकलता है जो sizeof(int) है। तीन नाम होने से आकार तीन या तीन गुना नहीं हो जाता; वह चूक सूची को array समझने से होती है। class, C में keyword नहीं है, इसलिए यहाँ tag नाम की तरह चल जाता है और कोई त्रुटि भी नहीं आती।
An enum is an integer type, and the number of names in its list does not change the size of a variable. The compiler gives an enum variable as much room as an int, so sizeof(m) is the same as sizeof(int). Three names do not make the size three, nor three times an int; that mistake comes from treating the list like an array. Also, class is not a keyword in C, so it works as an ordinary tag name.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
Pick the incorrect statement with respect to enums.
Aदो enum प्रतीकों का मान समान नहीं हो सकता हैTwo enum symbols cannot have the same value
Benum में केवल इन्टिजर कांस्टेंट की अनुमति हैOnly integer constants are allowed in enums
Cenum प्रतीकों के मान को बदलना संभव नहीं हैIt is not possible to change the value of enum symbols
Dयदि कोई मान असाइन नहीं किया गया है तो Enum वैरिएबल ऑटोमैटिक रूप से मान असाइन किए जाते हैंEnum variables are automatically assigned values if no value is specified
निम्नलिखित C कोड का आउटपुट क्या होगा? #include <stdio.h> enum hello { a,b=99,c,d=-1 }; int main() { enum hello m; printf("%d %d %d %d",a,b,c,d); }
What will be the output of the following C code? #include <stdio.h> enum hello { a,b=99,c,d=-1 }; int main() { enum hello m; printf("%d %d %d %d",a,b,c,d); }
निम्नलिखित C कोड का आउटपुट क्या होगा? #include <stdio.h> enum colour { blue, red, yellow }; int main() { enum colour c; c=yellow; printf("%d",c); }
What will be the output of the following C code? #include <stdio.h> enum colour { blue, red, yellow }; int main() { enum colour c; c=yellow; printf("%d",c); }
यदि कोड 32 बिट प्लेटफॉर्म पर चलाया जाए तो निम्नलिखित C कोड का आउटपुट क्या होगा? #include <stdio.h> enum fliqi { c = 0, d = 10, h = 20, s = 3 } a; int main() { a = c; printf("Size of enum variable = %d bytes", sizeof(a)); return 0; }
What will be the output of the following C code if the code is executed on a 32 bit platform? #include <stdio.h> enum fliqi { c = 0, d = 10, h = 20, s = 3 } a; int main() { a = c; printf("Size of enum variable = %d bytes", sizeof(a)); return 0; }