निम्न code को देखिए। typedef union unox { char cox; int gox; } uox; struct mox { char box; uox lox; } fox; निम्न में से कौन-सा statement सही assignment करता है?
Look at the following code. typedef union unox { char cox; int gox; } uox; struct mox { char box; uox lox; } fox; Which of the following statements makes a correct assignment?
Afox.uox.cox = 'p';
Bfox.lox.cox = 'p';
Cfox.lox.cox = "pp";
Dfox.fox.unox.cox = 'p';
सही उत्तर / Answer: (B)
हल / Solution
यहाँ typedef से union unox का नया नाम uox बना। struct mox के भीतर uox प्रकार का सदस्य lox है, और fox उसी struct का चर (variable) है। इसलिए union के सदस्य cox तक पहुँचने का रास्ता fox.lox.cox है। पहला विकल्प uox लिखता है, जो प्रकार का नाम है, सदस्य नहीं। तीसरा एक char खाने में string डाल रहा है। चौथे में fox.fox जैसा कोई सदस्य ही नहीं है। सो सही assignment fox.lox.cox = 'p'; ही है।
The typedef gives the union unox a new name, uox. Inside struct mox there is a member named lox of type uox, and fox is a variable of that struct. So the path to the union member cox is fox.lox.cox. Option 1 uses uox, which is a type name and not a member. Option 3 copies a string into a single char slot. Option 4 names fox.fox, which does not exist at all. Hence fox.lox.cox = 'p'; is correct.
function fun का return type struct student है, पर उस जगह तक struct student की परिभाषा नहीं आई है। परिभाषा function के अंदर लिखी है, इसलिए वह सिर्फ़ उसी block में दिखती है। बाहर struct student अधूरा (incomplete) प्रकार रह जाता है। अधूरे प्रकार को return type या main के चर का प्रकार नहीं बनाया जा सकता, इसलिए compile time error आता है। alan, Nothing या Varies कभी नहीं छपते।
The function fun has return type struct student, but at that point the structure has not been defined. The definition is written inside the function, so it is visible only inside that block. Outside, struct student stays an incomplete type. An incomplete type cannot be used as a return type or as the type of the variable in main, so a compile time error occurs. alan, Nothing or Varies never get printed.
इस C कोड का आउटपुट क्या है? int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d\n", *ptr, a); }
What is the output of this C code? int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d\n", *ptr, a); }
A10,10
B10,11
C11,10
D11,11
सही उत्तर / Answer: (D)
हल / Solution
ptr = &a से ptr, a की ओर इशारा करता है। *ptr += 1 का अर्थ है *ptr = *ptr + 1, यानी उस पते पर रखा मान, जो ख़ुद a है, 11 हो जाता है। अब *ptr और a एक ही मेमोरी खाना हैं, इसलिए दोनों 11 छपते हैं। आउटपुट 11,11 है। 10 वाले विकल्प भूल जाते हैं कि *ptr बदलने से a बदलता है, और 11,10 दोनों को अलग कॉपी मान लेता है।
ptr = &a makes ptr point to a. The statement *ptr += 1 means *ptr = *ptr + 1, so the value at that address, which is a itself, becomes 11. Now *ptr and a are the same memory location, so both print 11. The output is 11,11. Options with 10 forget that changing *ptr changes a, and 11,10 wrongly treats them as separate copies.
ऐरे और पॉइंटर्स के साथ C प्रोग्राम का आउटपुट क्या है?
#include<stdio.h>
void change(int[]);
int main(){
int a[3] = {20,30,40};
change(a);
printf("%d %d", *a, a[0]);
return 0;
}
void change(int a[]){
a[0] = 10;
}
What is the output of C Program with arrays and pointers?
#include<stdio.h>
void change(int[]);
int main(){
int a[3] = {20,30,40};
change(a);
printf("%d %d", *a, a[0]);
return 0;
}
void change(int a[]){
a[0] = 10;
}
A20 20
B10 20
C10 10
D20 30
सही उत्तर / Answer: (C)
हल / Solution
किसी फंक्शन को पूरा ऐरे भेजने पर सदस्यों की नक़ल नहीं बनती, सिर्फ़ उसका आधार पता जाता है। इसलिए change() के भीतर पहला सदस्य दस करने से असली ऐरे ही बदल जाता है। लौटकर तारा वाला रूप और a[0] दोनों उसी पहले सदस्य को पढ़ते हैं, सो दोनों जगह दस छपता है। साधारण चर में ऐसा नहीं होता — वहाँ नक़ल जाती है और भीतर का बदलाव बाहर नहीं दिखता।
Passing a whole array to a function does not copy its elements; only its base address travels. So setting the first element to ten inside change() really changes the original array. Back in main both the starred form and a[0] read that same first element, so ten is printed in both places. An ordinary variable behaves differently: a copy is passed and a change inside is not visible outside.
रिकर्सन से अपेक्षित परिणाम पाने के लिए किस C कीवर्ड का उपयोग करना ज़रूरी है?
What is the C keyword that must be used to achieve expected result using Recursion?
Aprintf
Bscanf
Cvoid
Dreturn
सही उत्तर / Answer: (D)
हल / Solution
recursion में हर कॉल का नतीजा अपनी पिछली कॉल तक पहुँचाना होता है। यह काम return करता है। जैसे fact(n) में return n * fact(n-1) लिखा जाता है। base case पर भी return 1 से रुकना होता है। बिना return के नतीजा ऊपर तक नहीं पहुँचता। printf और scanf कीवर्ड नहीं, लाइब्रेरी फ़ंक्शन हैं। void सिर्फ़ यह बताता है कि फ़ंक्शन कुछ नहीं लौटाता।
In recursion, the result of each call must be passed back to the call before it, and return does this. For example, fact(n) uses return n * fact(n-1), and the base case stops with return 1. Without return, the result never reaches the top. printf and scanf are library functions, not keywords, and void only says that a function returns nothing.
C कितने बुनियादी लूपिंग ढाँचों (looping constructs) का समर्थन करता है?
C supports how many basic looping constructs?
A2
B3
C4
D6
सही उत्तर / Answer: (B)
हल / Solution
C में तीन बुनियादी लूप हैं — for, while और do-while। for और while पहले शर्त जाँचते हैं, इसलिए इन्हें entry-controlled लूप कहते हैं। do-while पहले body चलाता है और बाद में शर्त देखता है, इसलिए यह exit-controlled है और कम से कम एक बार ज़रूर चलता है। goto से भी दोहराव बन सकता है, पर वह लूप का ढाँचा नहीं माना जाता। इसलिए सही उत्तर 3 है; 2, 4 और 6 ग़लत गिनती हैं।
C has three basic loops: for, while and do-while. The for and while loops check the condition first, so they are entry-controlled loops. The do-while loop runs its body first and checks the condition afterwards, so it is exit-controlled and always runs at least once. A goto can also repeat code, but it is not a looping construct. So the answer is 3, and the counts 2, 4 and 6 are wrong.
निम्नलिखित में से किन ऑपरेटरों की प्रीसीडेन्स समान है? P. "!=", Q. "+=", R. "<<="
Which operators of the following have the same precedence? P. "!=", Q. "+=", R. "<<="
AP और QP and Q
BQ और RQ and R
CP और RP and R
DP, Q और RP, Q and R
सही उत्तर / Answer: (B)
हल / Solution
+= और <<= दोनों compound assignment ऑपरेटर हैं। C में सभी assignment ऑपरेटर (=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=) एक ही precedence स्तर पर होते हैं। यह स्तर comma से ठीक ऊपर है। != एक equality ऑपरेटर है। इसकी precedence assignment से काफ़ी ऊँची है। इसलिए सिर्फ़ Q और R का स्तर समान है। जिस भी जोड़ी में P है, वह विकल्प ग़लत है।
Both += and <<= are compound assignment operators. In C every assignment operator (=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=) sits on one precedence level, just above the comma operator. The != operator is an equality operator, and its level is much higher than assignment. So only Q and R share the same precedence. Any option that pairs P with another operator is wrong.
संबंध ऑपरेटर (relational operator) बाएँ से दाएँ जुड़ते हैं, इसलिए हर पंक्ति में पहले 9 > 8 जाँचा जाता है और वह सच होकर 1 बनता है। अब x में 1 > 7 झूठा, सो शून्य; y में 1 > 0 सच, सो एक; z में 1 > 1 झूठा, सो शून्य। छपकर 0 1 0 आता है और विकल्प 2 सही है। ध्यान रखिए, गणित जैसी शृंखला यहाँ नहीं बनती।
Relational operators associate from left to right, so in each line 9 > 8 is tested first and yields 1. For x, 1 > 7 is false, giving zero; for y, 1 > 0 is true, giving one; for z, 1 > 1 is false, giving zero. The printed result is 0 1 0, so option 2 is correct. Note that such a comparison is not a chain as in mathematics.
निम्नलिखित में से कौन सा स्टोरेज स्पेसिफायर/क्लास है?
Which of the following is a storage specifier/class?
Aenum
Bunion
Cauto
Dvolatile
सही उत्तर / Answer: (C)
हल / Solution
C में चार storage class specifier हैं — auto, register, static और extern (व्याकरण में typedef को भी इन्हीं के साथ गिना जाता है)। इनमें से auto विकल्पों में मौजूद है। enum और union नए डेटा टाइप बनाने के कीवर्ड हैं, storage class नहीं। volatile एक type qualifier है, जो बताता है कि वेरिएबल का मान प्रोग्राम के बाहर से बदल सकता है। इसलिए सही उत्तर auto है।
C has four storage class specifiers: auto, register, static and extern (typedef is also grouped with them in the grammar). Of these, auto appears in the options. enum and union are keywords for creating new data types, not storage classes. volatile is a type qualifier, which says a variable's value may change from outside the program. So the correct answer is auto.
निम्नलिखित में से कौन-सी C में मान्य घोषणा (declaration) नहीं है? 1. short int x; 2. signed short x; 3. short x; 4. unsigned short x;
Which of the following is not a valid declaration in C? 1. short int x; 2. signed short x; 3. short x; 4. unsigned short x;
A3 और 43 and 4
Bकेवल 2only 2
Cकेवल 1only 1
Dसभी मान्य हैंAll are valid
सही उत्तर / Answer: (D)
हल / Solution
C में short, long, signed और unsigned को modifier कहते हैं। इनके साथ int लिखना ज़रूरी नहीं, वह अपने आप मान लिया जाता है। इसलिए short x; का अर्थ short int x; है। signed short x; का अर्थ signed short int x; है। unsigned short x; का अर्थ unsigned short int x; है। चारों घोषणाएँ बिना error के compile होती हैं। इसलिए सही उत्तर "सभी मान्य हैं" है।
In C, short, long, signed and unsigned are modifiers. Writing int after them is optional, because int is assumed. So short x; means short int x;. signed short x; means signed short int x;. unsigned short x; means unsigned short int x;. All four declarations compile without any error. So the correct answer is "All are valid", and the other options are wrong.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति