पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define MIN 0);
#ifdef MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN
return 0;
}
What will be the output of the following C code?
#include <stdio.h>
#define MIN 0);
#ifdef MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN
return 0;
}
A10 0
Bprintf की गलत syntax के कारण कम्पाइल टाइम एररCompile time error due to illegal syntax for printf
Cअपरिभाषित व्यवहारUndefined behaviour
DMIN के गलत मान के कारण कम्पाइल टाइम एररCompile time error due to illegal MIN value
सही उत्तर / Answer: (A)
हल / Solution
MIN का पाठ "0);" है। #ifdef MIN सिर्फ़ यह देखता है कि MIN परिभाषित है या नहीं, उसका मान नहीं, इसलिए MAX 10 बन जाता है। अब printf("%d %d\n", MAX, MIN फैलकर printf("%d %d\n", 10, 0); बनता है। अधूरा दिखने वाला printf macro से पूरा हो जाता है। इसलिए कोड सही चलता है और 10 0 छपता है। preprocessor macro के पाठ में कोष्ठक या semicolon पर आपत्ति नहीं करता, इसलिए विकल्प 2 और 4 ग़लत हैं।
The text of MIN is "0);". #ifdef MIN only checks whether MIN is defined, not its value, so MAX becomes 10. Then printf("%d %d\n", MAX, MIN expands to printf("%d %d\n", 10, 0);. The printf that looks incomplete is completed by the macro. So the code runs and prints 10 0. The preprocessor does not object to brackets or a semicolon in a macro, so options 2 and 4 are wrong, and so is option 3.
प्रश्न 2उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define MIN 0
#if MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#if MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
A10 0
Bकम्पाइल टाइम एररCompile time error
Cअपरिभाषित व्यवहारUndefined behaviour
Dउल्लिखित में से कोई नहींNone of the mentioned
सही उत्तर / Answer: (B)
हल / Solution
MIN का मान 0 है, इसलिए #if MIN की शर्त झूठी है। उसके भीतर का #define MAX 10 हट जाता है, यानी MAX कभी परिभाषित नहीं होता। अब printf में MAX जस का तस बचता है और compiler उसे एक अनजान identifier मानता है। इसलिए "undeclared identifier" की compile time error आती है। 10 0 तब छपता जब #ifdef MIN लिखा होता, क्योंकि MIN परिभाषित है, भले उसका मान 0 हो। यहाँ undefined behaviour नहीं है, error पक्की है।
MIN has the value 0, so the condition #if MIN is false. The #define MAX 10 inside it is dropped, so MAX is never defined. In printf, MAX stays as it is, and the compiler sees it as an unknown identifier. So an "undeclared identifier" compile time error occurs. 10 0 would be printed only with #ifdef MIN, because MIN is defined even though its value is 0. There is no undefined behaviour here; the error is certain.
प्रश्न 3उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define COLD
int main()
{
#ifdef COLD
printf("COLD\t");
#undef COLD
#endif
#ifdef COLD
printf("HOT\t");
#endif
}
What will be the output of the following C code?
#include <stdio.h>
#define COLD
int main()
{
#ifdef COLD
printf("COLD\t");
#undef COLD
#endif
#ifdef COLD
printf("HOT\t");
#endif
}
AHOT
BCOLD
CCOLD HOT
Dकोई आउटपुट नहींNo Output
सही उत्तर / Answer: (B)
हल / Solution
शुरू में COLD परिभाषित है, इसलिए पहले #ifdef COLD का भाग बना रहता है। उसमें printf("COLD\t") है, और #undef COLD से macro हट जाता है। preprocessor ऊपर से नीचे चलता है, इसलिए दूसरे #ifdef COLD तक COLD परिभाषित नहीं रहता। वह भाग हट जाता है और HOT वाला printf compile ही नहीं होता। इसलिए आउटपुट सिर्फ़ COLD है, उसके बाद एक tab। COLD HOT या केवल HOT ग़लत हैं, और कुछ न छपना भी ग़लत है।
At the start COLD is defined, so the first #ifdef COLD block is kept. It holds printf("COLD\t"), and #undef COLD then removes the macro. The preprocessor works from top to bottom, so by the second #ifdef COLD, COLD is no longer defined. That block is dropped, and the HOT printf is never compiled. So the output is only COLD, followed by a tab. COLD HOT and HOT alone are wrong, and "No Output" is wrong too, because COLD is printed.
प्रश्न 4उत्तर + हल
कंडीशनल इन्क्लूज़न में "else if" किसके द्वारा लिखा जाता है?
The “else if” in conditional inclusion is written by?
A#else if
B#elseif
C#elsif
D#elif
सही उत्तर / Answer: (D)
हल / Solution
conditional inclusion में "else if" के लिए C का directive #elif है। इसका रूप है: #if शर्त1 … #elif शर्त2 … #else … #endif। #elif की शर्त तभी देखी जाती है जब ऊपर की सारी शर्तें झूठी हों। #else if में preprocessor #else को पहचानता है और बाद का if फालतू पाठ बन जाता है, इसलिए वह else if का काम नहीं करता। #elseif और #elsif नाम के directive C में हैं ही नहीं। इसलिए सही उत्तर #elif है।
In conditional inclusion, the C directive for "else if" is #elif. Its form is #if condition1 ... #elif condition2 ... #else ... #endif. The #elif condition is checked only when all earlier conditions are false. In #else if, the preprocessor sees #else and treats the following if as extra text, so it does not work as else if. Directives named #elseif or #elsif do not exist in C at all. So the correct answer is #elif, option 4.
प्रश्न 5उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define Cprog
int main()
{
int a = 2;
#ifdef Cprog
a = 1;
printf("%d", Cprog);
}
What will be the output of the following C code?
#include <stdio.h>
#define Cprog
int main()
{
int a = 2;
#ifdef Cprog
a = 1;
printf("%d", Cprog);
}
Aचलाने पर कोई आउटपुट नहींNo output on execution
Bआउटपुट 1Output as 1
Cआउटपुट 2Output as 2
Dकम्पाइल टाइम एररCompile time error
सही उत्तर / Answer: (D)
हल / Solution
इस कोड में दो गलतियाँ हैं। पहली, #ifdef Cprog खोला गया है पर उसका #endif कहीं नहीं है। हर #if या #ifdef को #endif से बंद करना ज़रूरी है, वरना "unterminated conditional directive" error आती है। दूसरी, Cprog एक ख़ाली macro है, इसलिए printf("%d", Cprog) फैलकर printf("%d", ) बनता है, जो अधूरा भाव है। दोनों कारणों से program compile नहीं होता, इसलिए 1, 2 या ख़ाली आउटपुट का सवाल ही नहीं उठता।
This code has two mistakes. First, #ifdef Cprog is opened but never closed with #endif. Every #if or #ifdef must end with #endif, otherwise an "unterminated conditional directive" error appears. Second, Cprog is an empty macro, so printf("%d", Cprog) expands to printf("%d", ), which is an incomplete expression. For both reasons the program does not compile, so there is no question of printing 1, 2 or nothing. The answer is compile time error.
प्रश्न 6उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define SYSTEM 20
int main()
{
int a = 20;
#if SYSTEM == a
printf("HELLO ");
#endif
#if SYSTEM == 20
printf("WORLD\n");
#endif
}
What will be the output of the following C code?
#include <stdio.h>
#define SYSTEM 20
int main()
{
int a = 20;
#if SYSTEM == a
printf("HELLO ");
#endif
#if SYSTEM == 20
printf("WORLD\n");
#endif
}
AHELLO
BWORLD
CHELLO WORLD
Dकोई आउटपुट नहींNo Output
सही उत्तर / Answer: (B)
हल / Solution
#if की शर्त preprocessing के समय जाँची जाती है, जब variable बने ही नहीं होते। इसलिए #if SYSTEM == a में a एक अनजान identifier है, और #if में ऐसे हर identifier को 0 मान लिया जाता है। शर्त 20 == 0 बनती है, जो झूठी है, इसलिए HELLO वाली पंक्ति हट जाती है। दूसरी शर्त 20 == 20 सच है, इसलिए WORLD छपता है। int a = 20 का #if पर असर नहीं होता।
An #if condition is checked during preprocessing, before any variable exists. So in #if SYSTEM == a, a is an unknown identifier, and #if treats every such identifier as 0. The condition becomes 20 == 0, which is false, so the HELLO line is removed. The second condition, 20 == 20, is true, so WORLD is printed. int a = 20 has no effect on #if, so HELLO WORLD is wrong, and so is "No Output".
प्रश्न 7उत्तर + हल
निम्नलिखित C कोड के आउटपुट पर टिप्पणी कीजिए
#include <stdio.h>
#define var 20);
int main()
{
printf("%d\n", var
}
Comment on the output of the following C code
#include <stdio.h>
#define var 20);
int main()
{
printf("%d\n", var
}
Aकोई एरर नहीं, यह आउटपुट 20 दिखाएगाNo errors, it will show the output 20
Bकम्पाइल टाइम एरर, printf के कोष्ठक बंद नहीं होतेCompile time error, the printf braces aren’t closed
Cकम्पाइल टाइम एरर, #define में कोई खुला कोष्ठक नहीं हैCompile time error, there are no open braces in #define
Dउल्लिखित में से कोई नहींNone of the mentioned
सही उत्तर / Answer: (A)
हल / Solution
#define var 20); में var का पाठ "20);" है, यानी संख्या, बंद कोष्ठक और semicolon। preprocessor सिर्फ़ पाठ बदलता है, वह कोष्ठकों के जोड़े नहीं गिनता। इसलिए printf("%d\n", var फैलकर printf("%d\n", 20); बन जाता है। अब कोष्ठक पूरे हैं और statement सही है, इसलिए 20 छपता है। printf का कोष्ठक macro से बंद हो जाता है, इसलिए विकल्प 2 ग़लत है। macro में अकेला बंद कोष्ठक होना भी वैध है, इसलिए विकल्प 3 भी ग़लत है।
In #define var 20); the text of var is "20);", a number, a closing bracket and a semicolon. The preprocessor only replaces text; it does not check that brackets are paired. So printf("%d\n", var becomes printf("%d\n", 20);. Now the brackets match, the statement is valid, and 20 is printed. The macro closes the printf bracket, so option 2 is wrong. A lone closing bracket in a macro is allowed, so option 3 is wrong too.
प्रश्न 8उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
#define A 1 + 2
#define B 3 + 4
int main()
{
int var = A * B;
printf("%d\n", var);
}
What will be the output of the following C code?
#include <stdio.h>
#define A 1 + 2
#define B 3 + 4
int main()
{
int var = A * B;
printf("%d\n", var);
}
A9
B11
C12
D21
सही उत्तर / Answer: (B)
हल / Solution
A और B पाठ के रूप में फैलते हैं, कोष्ठक के साथ नहीं। इसलिए A * B बनता है 1 + 2 * 3 + 4। गुणा पहले होता है, तो 2 * 3 = 6, फिर 1 + 6 + 4 = 11। कोष्ठक होते तो (1 + 2) * (3 + 4) = 21 आता; यही भटकाने वाला विकल्प है। इस पाठ से न 9 बनता है, न 12। इसलिए macro के पाठ को कोष्ठक में लिखिए।
A and B expand as plain text, without brackets. So A * B becomes 1 + 2 * 3 + 4. Multiplication comes first, so 2 * 3 = 6, then 1 + 6 + 4 = 11. With brackets, (1 + 2) * (3 + 4) would give 21, which is the trap option. Neither 9 nor 12 comes out of this text. That is why macro bodies should be wrapped in brackets.
प्रश्न 9उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
# define max
void m()
{
printf("hi");
}
void main()
{
max;
m();
}
What will be the output of the following C code?
#include <stdio.h>
# define max
void m()
{
printf("hi");
}
void main()
{
max;
m();
}
Aरन टाइम एररRun time error
Bhi hi
Cकुछ नहीं (Nothing)Nothing
Dhi
सही उत्तर / Answer: (D)
हल / Solution
# define max में max के बाद कोई पाठ नहीं है, यानी max एक ख़ाली macro है। # और define के बीच space भी वैध है। main में max; फैलकर सिर्फ़ ; बचता है, जो एक ख़ाली statement है और कुछ नहीं करता। इसके बाद m() एक बार चलता है और hi छपता है। m() दोबारा नहीं बुलाया गया, इसलिए hi hi ग़लत है। कोड वैध है, इसलिए न run time error आता है, न आउटपुट ख़ाली रहता है।
In # define max, nothing follows max, so max is an empty macro. A space between # and define is also allowed. In main, max; expands to just ;, which is an empty statement and does nothing. Then m() runs once and prints hi. m() is not called a second time, so hi hi is wrong. The code is valid, so there is no run time error and the output is not empty. The correct answer is hi.
प्रश्न 10उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
#define max 45
max = 32;
printf("%d", max);
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
#define max 45
max = 32;
printf("%d", max);
}
A32
B45
Cकम्पाइल टाइम एररCompile time error
Dबदलता रहता है (Varies)Varies
सही उत्तर / Answer: (C)
हल / Solution
#define max 45 के बाद max कोई variable नहीं रहता, वह सीधे 45 से बदल जाता है। इसलिए max = 32; फैलकर 45 = 32; बनता है। assignment के बाईं ओर ऐसी चीज़ चाहिए जिसकी memory में जगह हो, यानी lvalue। 45 एक स्थिर संख्या है, उसमें कुछ रखा नहीं जा सकता, इसलिए compiler error देता है। program बनता ही नहीं, तो 32 या 45 नहीं छपता। हर compiler यह पकड़ता है, इसलिए Varies भी ग़लत है।
After #define max 45, max is not a variable; it is simply replaced by 45. So max = 32; becomes 45 = 32;. The left side of an assignment must be something stored in memory, called an lvalue. 45 is a constant, so nothing can be stored in it, and the compiler reports an error. The program is never built, so neither 32 nor 45 is printed. Every compiler catches this, so "Varies" is wrong.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
यदि फ़ाइल का नाम कोण कोष्ठक (angle brackets) में लिखा हो, तो ___________
If the file name is enclosed in angle brackets, then ___________
Aप्रीप्रोसेसर इसे यूजर-डिफ़ाइंड फ़ाइल के रूप में मानता हैThe preprocessor treats it as a user-defined file
Bप्रीप्रोसेसर इसे सिस्टम-डिफ़ाइंड फ़ाइल के रूप में मानता हैThe preprocessor treats it as a system-defined file
Cप्रीप्रोसेसर इसे यूजर-डिफ़ाइंड फ़ाइल और सिस्टम-डिफ़ाइंड फ़ाइल के रूप में मानता हैThe preprocessor treats it as a user-defined file & system-defined file
Aप्रीप्रोसेसर को फ़ाइल के टेक्स्ट को पकड़ने और इसे सीधे वर्तमान फ़ाइल में रखने के लिए कहता हैtells the preprocessor to grab the text of the file and place it directly in the current file
Bइन स्टेटमेंट्स को एक प्रोग्राम के शीर्ष पर रखा जाना चाहिएthese statements should be placed at the top of a program