पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
typedef डिक्लेरेशन क्या है?
What is typedef declaration?
Aकोई नया प्रकार नहीं बनाता हैDoes not create a new type
Bयह केवल कुछ मौजूदा प्रकार के लिए एक नया नाम जोड़ता हैIt merely adds a new name for some existing type
Cकोई नया प्रकार नहीं बनाता है, यह केवल कुछ मौजूदा प्रकार के लिए एक नया नाम जोड़ता हैDoes not create a new type, It merely adds a new name for some existing type
Dउल्लिखित में से कोई नहींNone of the mentioned
सही उत्तर / Answer: (C)
हल / Solution
typedef कोई नया डाटा टाइप (data type) नहीं बनाता; वह किसी पहले से मौजूद टाइप को दूसरा नाम, यानी उपनाम (alias), दे देता है। typedef int integer; लिखने पर integer और int एक ही टाइप रहते हैं, कोई तीसरा टाइप नहीं बनता। विकल्प 1 और 2 इसी एक बात के आधे-आधे हिस्से हैं, इसलिए अकेले अधूरे हैं। विकल्प 3 दोनों हिस्से साथ कहता है, सो पूरी परिभाषा वही है, और विकल्प 4 ग़लत है क्योंकि सही कथन मौजूद है।
A typedef does not create a new data type. It only gives an existing type a second name, that is an alias. After typedef int integer; the names integer and int mean exactly the same type, so nothing new comes into being. Options 1 and 2 are the two halves of this single idea, so each alone is incomplete. Option 3 states both halves, which is the full definition.
प्रश्न 2उत्तर + हल
typedef के बारे में निम्नलिखित में से कौन-सा कथन असत्य है?
Which of the following is false about typedef?
Atypedef स्कोप नियमों का पालन करता हैtypedef follow scope rules
Btypedef से परिभाषित विकल्पों को दोबारा परिभाषित किया जा सकता है। (उदाहरण: typedef char a; typedef int a;)typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;)
Cआप किसी typedef को दूसरे टर्म के साथ typedef कर सकते हैंYou can typedef a typedef with other term
Dउल्लिखित सभीAll of the mentioned
सही उत्तर / Answer: (B)
हल / Solution
दूसरा कथन असत्य है। एक ही क्षेत्र (scope) में किसी typedef नाम को दोबारा दूसरे प्रकार से नहीं बाँधा जा सकता, सो उदाहरण में दिए दोनों typedef एक साथ लिखने पर टकराव की त्रुटि आती है। पहला कथन सही है, क्योंकि typedef नाम चरों की तरह क्षेत्र के नियम मानते हैं। तीसरा भी सही है, क्योंकि एक typedef के ऊपर दूसरा typedef बनाया जा सकता है। दो कथन सही होने से चौथा विकल्प अपने-आप ग़लत हो जाता है।
The second statement is the false one. Within the same scope a typedef name cannot be bound again to a different type, so writing both typedef lines of the example together gives a conflicting types error. The first statement is true, because typedef names obey scope rules just as variables do. The third is true as well, since one typedef can be built on top of another. As two statements are true, the fourth choice fails.
प्रश्न 3उत्तर + हल
दिए गए विकल्पों में से आरंभीकरण (initialization) का सही तरीक़ा कौन-सा है?
typedef char *string;
Which of the given options is the correct method for initialization?
typedef char *string;
A*string *p = "Hello";
Bstring p = "Hello";
C*string p = 'A';
Dtypedef का उपयोग करते समय एक से अधिक स्थान नहीं दिया जाना चाहिएNot more than one space should be given when using typedef
सही उत्तर / Answer: (B)
हल / Solution
typedef वाली पंक्ति से string नाम उस प्रकार का पर्याय बन जाता है जो char का सूचक है। इसलिए दूसरा रूप भीतर से char का सूचक बनाकर उसमें डोरी का पता रख देता है, और यही सही आरंभीकरण है। पहले विकल्प में एक अतिरिक्त तारा लग गया है, जिससे सूचक का सूचक बन जाता है। तीसरे में अक्षर स्थिरांक दिया है, डोरी नहीं। चौथे का typedef से कोई लेना-देना नहीं, जगह गिनने का कोई नियम होता ही नहीं।
The typedef line makes the name string stand for the type pointer to char. So the second form really declares a pointer to char and stores the address of the string in it, and that is the correct initialization. The first choice adds one more star, which turns it into a pointer to a pointer. The third assigns a character constant instead of a string. The fourth has nothing to do with typedef, since spacing makes no difference.
प्रश्न 4उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef struct p
{
int x, y;
}k;
int main()
{
struct p p = {1, 2};
k k1 = p;
printf("%d\n", k1.x);
}
What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
}k;
int main()
{
struct p p = {1, 2};
k k1 = p;
printf("%d\n", k1.x);
}
Aकम्पाइल टाइम एररCompile time error
B1
C0
D2
सही उत्तर / Answer: (B)
हल / Solution
इस typedef से दो नाम बनते हैं — struct p और उसका छोटा नाम k, और दोनों एक ही प्रकार हैं। इसलिए संरचना भरते समय x में एक और y में दो बैठता है, और अगली पंक्ति पूरी संरचना की नक़ल k1 में कर देती है। C में एक ही प्रकार की संरचना दूसरी में सीधे रखी जा सकती है, सो कोई त्रुटि नहीं आती। k1.x वही एक है, इसलिए एक छपता है; दो तो y का मान है।
This typedef creates two names, struct p and the shorter name k, and both stand for the same type. So while filling the structure, one goes into x and two into y, and the next line copies the whole structure into k1. Assigning one structure to another of the same type is allowed in C, so no error occurs. Then k1.x is still one, which is what gets printed, while two is the value of y.
प्रश्न 5उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}
What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}
Aकम्पाइल टाइम एररCompile time error
B1
C0
Dमानक पर निर्भर करता हैDepends on the standard
सही उत्तर / Answer: (A)
हल / Solution
typedef वाली घोषणा में आरंभिक मान (initializer) नहीं दिया जा सकता, पर यहाँ k को उपनाम (alias) बनाकर उसी में {1, 2} भी भर दिया गया है; संकलक (compiler) इसे अस्वीकार कर देता है। दूसरी चूक आगे है — p केवल टैग (tag) है, टाइप नहीं, इसलिए p k1 भी ग़लत है और वहाँ struct p k1; चाहिए था। दो-दो कारणों से संकलन रुक जाता है, सो उत्तर कम्पाइल टाइम एरर है और 1 छपने का सवाल नहीं।
A typedef declaration cannot carry an initializer, yet here k is made an alias and is also filled with {1, 2} in the same line, which the compiler rejects. There is a second fault too: p is only the structure tag and not a type name, so p k1 is wrong and struct p k1; would be needed. Two faults stop compilation, so the answer is a compile time error.
प्रश्न 6उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}
What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}
Aकम्पाइल टाइम एररCompile time error
B1
C0
Dमानक पर निर्भर करता हैDepends on the standard
सही उत्तर / Answer: (A)
हल / Solution
typedef लिखने पर आगे उपनाम (alias) देना ज़रूरी है, जैसे typedef struct p { int x, y; } k;। यहाँ घोषणा में कोई उपनाम ही नहीं दिया गया, इसलिए p नाम का कोई टाइप बनता ही नहीं — p केवल structure का टैग (tag) है और struct p लिखकर ही चलता है। आगे p k1 लिखा है, सो संकलक (compiler) वहीं रुक जाता है और कम्पाइल टाइम एरर मिलता है।
A typedef must be followed by an alias name, as in typedef struct p { int x, y; } k;. Here the declaration gives no alias, so no type named p comes into being; p is only the structure tag and works only as struct p. The next line writes p k1, so the compiler refuses to treat p as a type name and stops with a compile time error.
प्रश्न 7उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef int integer;
int main()
{
int i = 10, *ptr;
float f = 20;
integer j = i;
ptr = &j;
printf("%d\n", *ptr);
return 0;
}
What will be the output of the following C code?
#include <stdio.h>
typedef int integer;
int main()
{
int i = 10, *ptr;
float f = 20;
integer j = i;
ptr = &j;
printf("%d\n", *ptr);
return 0;
}
Aकम्पाइल टाइम एररCompile time error
B20
Cएड्रेसAddress
D10
सही उत्तर / Answer: (D)
हल / Solution
typedef int integer; के बाद integer और int एक ही टाइप हैं, इसलिए integer j = i; से j में 10 चला जाता है। फिर ptr = &j; से पॉइंटर (pointer) j के पते पर पहुँचता है और *ptr उसी खाने का मान, यानी 10, लौटाता है। float चर f घोषित तो है पर इस्तेमाल नहीं हुआ, सो 20 छप नहीं सकता। %d के साथ *ptr मान छापता है, पता नहीं।
After typedef int integer; the names integer and int mean the same type, so integer j = i; puts 10 into j. Then ptr = &j; makes the pointer hold the address of j, and *ptr reads the value stored there, which is 10. The float variable f is declared but never used, so 20 cannot be printed. With %d the expression *ptr prints a value, not an address.
प्रश्न 8उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
stu s;
s.a = "hi";
printf("%s", s.a);
}
What will be the output of the following C code?
#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
stu s;
s.a = "hi";
printf("%s", s.a);
}
Aकम्पाइल टाइम एररCompile time error
Bबदलता रहता हैVaries
Chi
Dh
सही उत्तर / Answer: (C)
हल / Solution
यहाँ stu उपनाम (typedef alias) है, इसलिए stu s; पूरी तरह वैध घोषणा है। structure के भीतर char *a; एक कैरेक्टर पॉइंटर (character pointer) है, और s.a = "hi"; उसमें स्ट्रिंग लिटरल (string literal) का पता भर देता है। printf में %s उस पते से शुरू होकर पूरी स्ट्रिंग छापता है, इसलिए आउटपुट hi है। केवल पहला अक्षर h तब आता जब %c लगाया गया होता। कोड वैध है, सो न एरर मिलता है और न आउटपुट बदलता है।
Here stu is a typedef alias, so stu s; is a perfectly valid declaration. Inside the structure char *a; is a character pointer, and s.a = "hi"; stores the address of the string literal in it. In printf the %s specifier starts at that address and prints the whole string, so the output is hi. Only the first letter h would appear if %c had been used instead.
प्रश्न 9उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
struct stu s;
s.a = "hi";
printf("%s", s.a);
}
What will be the output of the following C code?
#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
struct stu s;
s.a = "hi";
printf("%s", s.a);
}
Aकम्पाइल टाइम एररCompile time error
Bबदलता रहता हैVaries
Chi
Dh
सही उत्तर / Answer: (A)
हल / Solution
typedef struct student { ... } stu; में stu एक उपनाम (typedef alias) है, structure का टैग (tag) नहीं; टैग तो student है। इसलिए चर बनाने के दो ही सही रूप हैं — stu s; या struct student s;। प्रोग्राम में struct stu s; लिखा है, और संकलक (compiler) struct stu नाम का कोई structure नहीं ढूँढ़ पाता, इसलिए कम्पाइल टाइम एरर आता है। संकलन ही नहीं होता, सो hi या h छपने की नौबत नहीं आती।
In typedef struct student { ... } stu; the name stu is a typedef alias and not the structure tag; the tag here is student. So a variable may be made in only two correct ways: stu s; or struct student s;. The program writes struct stu s;, and the compiler finds no structure tagged stu, so it reports a compile time error. Compilation fails, which is why neither hi nor h can be printed.
प्रश्न 10उत्तर + हल
निम्न C कोड का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
struct p
{
char *name;
struct p *next;
};
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
strcpy(q.name, p.name);
ptrary[1] = &q;
printf("%s\n", ptrary[1]->name);
return 0;
}
What will be the output of the following C code?
#include <stdio.h>
int main()
{
struct p
{
char *name;
struct p *next;
};
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
strcpy(q.name, p.name);
ptrary[1] = &q;
printf("%s\n", ptrary[1]->name);
return 0;
}
Aकम्पाइल टाइम एररCompile time error
Bकंपाइलर पर निर्भर करता हैDepends on the compiler
Cअपरिभाषित व्यवहारUndefined behaviour
Dxyz
सही उत्तर / Answer: (A)
हल / Solution
इस कोड में ptrary नाम का कोई चर (variable) कहीं घोषित ही नहीं हुआ है, फिर भी उसे सरणी (array) की तरह इस्तेमाल किया गया है। बिना घोषणा वाला नाम देखकर संकलक (compiler) वहीं रुक जाता है, इसलिए कम्पाइल टाइम एरर मिलता है। प्रोग्राम चलता ही नहीं, सो xyz छपने का सवाल नहीं। चूक निश्चित है — न कंपाइलर पर निर्भर, न अपरिभाषित व्यवहार (undefined behaviour), क्योंकि वे संकलित प्रोग्राम में ही दिखते हैं।
The variable ptrary is never declared anywhere in this program, yet it is used as an array. An undeclared identifier stops the compiler immediately, so the program gives a compile time error. Since compilation never finishes, nothing runs and printing xyz is impossible. The fault is a fixed one, not compiler dependent, and it is not undefined behaviour either, because both of those need a program that compiles first.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति