पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int a=10;
int *p = a;
int *r = &p;
printf("%d", (**r));
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a=10;
int *p = a;
int *r = &p;
printf("%d", (**r));
}
A1
BCompile time error
Ca का पताAddress of a
Dकचरा मानJunk value
सही उत्तर / Answer: (B)
हल / Solution
यहाँ r का प्रकार int * है, यानी एक ही स्तर का pointer। *r एक int देता है। printf में **r लिखा है, यानी उस int को फिर dereference करना, जो संभव नहीं। इसलिए compiler त्रुटि देता है — indirection requires pointer operand। साथ ही int *p = a; में int मान सीधे pointer में रखा गया है, जिसे आज का compiler भी रोकता है। program बनता ही नहीं, इसलिए कुछ नहीं छपता।
Here r has type int *, so it is a single-level pointer. *r gives an int, and the printf uses **r, which tries to dereference that int again. That is not allowed, so the compiler stops with an error like indirection requires pointer operand. Also, int *p = a; puts a plain int into a pointer, which modern compilers also reject. The program never builds, so nothing like 1, an address or junk is printed.
प्रश्न 2उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
A5
BCompile time error
C6
Dकचरा मान (Junk)Junk
सही उत्तर / Answer: (C)
हल / Solution
यहाँ p में k का पता है और m में p का पता है, यानी m एक pointer टू pointer है। *m से p मिलता है, और **m से वह मिलता है जिसे p point करता है, यानी k। इसलिए **m = 6; सीधे k में 6 रख देता है। फिर k छापने पर 6 आता है। 5 पुराना मान था। प्रकार सही मेल खाते हैं, इसलिए compile error नहीं। k initialize है, इसलिए कचरा भी नहीं।
Here p holds the address of k and m holds the address of p, so m is a pointer to a pointer. *m gives p, and **m gives what p points to, which is k. So **m = 6; stores 6 directly into k, and printing k gives 6. The value 5 is the old value that has now been changed. All the types match, so there is no compile error. Since k is initialized, no junk value appears.
प्रश्न 3उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **p);
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **p);
}
A5 5 5
B5 5 कचरा मान5 5 junk value
C5 कचरा कचरा5 junk junk
DCompile time error
सही उत्तर / Answer: (D)
हल / Solution
यहाँ p का प्रकार int * है, यानी इसमें सिर्फ़ एक स्तर का पता है। *p से k का मान 5 मिलता है, जो एक int है। printf में **p लिखा है, यानी उस int को फिर से dereference करना। int कोई pointer नहीं है, इसलिए compiler त्रुटि देता है — indirection requires pointer operand। शायद लिखने वाला **m लिखना चाहता था, जिससे 5 5 5 छपता। पर जैसा लिखा है, program बनता ही नहीं, इसलिए कोई मान नहीं छपता।
Here p has type int *, so it has only one level of address. *p gives the value of k, which is 5, an int. The printf uses **p, which tries to dereference that int again. An int is not a pointer, so the compiler stops with an error like indirection requires pointer operand. Perhaps **m was intended, which would print 5 5 5. But as written, the program never builds, so no values are printed.
प्रश्न 4उत्तर + हल
निम्नलिखित में से कौन सा लॉजिकल ऑपरेशन पॉइंटर्स पर लागू किया जा सकता है?
(प्रारंभिक मान मानते हुए int *a = 2; int *b = 3;)
Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
Aa | b
Ba ^ b
Ca & b
Dइनमें से कोई नहींNone of the mentioned
सही उत्तर / Answer: (D)
हल / Solution
|, ^ और & bitwise operators हैं। C में इनके दोनों operands पूर्णांक प्रकार के होने चाहिए। a और b pointers हैं, इसलिए a | b, a ^ b या a & b लिखते ही compiler त्रुटि देता है — invalid operands to binary expression। pointers पर सिर्फ़ कुछ ही काम चलते हैं: पूर्णांक जोड़ना-घटाना, दो pointers घटाना और उनकी तुलना करना। इसलिए दिए गए तीनों में से कोई भी लागू नहीं होता, और उत्तर 'इनमें से कोई नहीं' है।
The symbols |, ^ and & are bitwise operators, and in C both their operands must be integers. Here a and b are pointers, so a | b, a ^ b or a & b gives a compile error like invalid operands to binary expression. Only a few operations work on pointers: adding or subtracting an integer, subtracting two pointers and comparing them. So none of the three applies, and the answer is None of the mentioned.
प्रश्न 5उत्तर + हल
32-बिट मशीन में *ptr का आकार क्या है (इनिशियलाइज़ेशन को int *ptr = 10; मानकर)?
What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
A1
B2
C4
D8
सही उत्तर / Answer: (C)
हल / Solution
यहाँ ptr एक int pointer है, इसलिए *ptr का प्रकार int है। sizeof(*ptr) असल में sizeof(int) के बराबर होता है। 32-बिट मशीन पर int का आकार 4 byte होता है, इसलिए उत्तर 4 है। ध्यान दीजिए, sizeof सिर्फ़ प्रकार देखता है, ptr में रखे पते 10 पर जाकर कुछ पढ़ता नहीं। 1 byte char का आकार है। 2 byte पुराने 16-बिट compilers का int है। 8 byte double का आकार है।
Here ptr is an int pointer, so *ptr has the type int. That means sizeof(*ptr) is the same as sizeof(int). On a 32-bit machine an int takes 4 bytes, so the answer is 4. Note that sizeof only looks at the type and never reads anything at address 10. One byte is the size of a char, 2 bytes is an int on old 16-bit compilers, and 8 bytes is the size of a double.
प्रश्न 6उत्तर + हल
निम्नलिखित में से कौन-सा अंकगणितीय operation pointers a और b पर लागू किया जा सकता है?
(मान लीजिए int *a = (int *)2; int *b = (int *)3;)
Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
Aa + b
Ba – b
Ca * b
Da / b
सही उत्तर / Answer: (B)
हल / Solution
दो pointers के बीच C सिर्फ़ घटाने की अनुमति देता है। a – b बताता है कि दोनों पतों के बीच कितने तत्व हैं, इसलिए इसका अर्थ बनता है। दो पतों को जोड़ने, गुणा करने या भाग देने से कोई उपयोगी पता नहीं बनता। इसलिए a + b, a * b और a / b पर compiler त्रुटि देता है। ध्यान रहे, घटाने का परिणाम तभी भरोसेमंद है जब दोनों pointers एक ही array में हों।
Between two pointers, C allows only subtraction. The result of a – b tells how many elements lie between the two addresses, so it has a meaning. Adding, multiplying or dividing two addresses gives no useful address, so a + b, a * b and a / b all cause a compile error. Keep in mind that the subtraction result is only reliable when both pointers point into the same array.
प्रश्न 7उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf("%d", p + q);
}
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf("%d", p + q);
}
A2
B3
C5
DCompile time error
सही उत्तर / Answer: (D)
हल / Solution
C में दो pointers को आपस में जोड़ने की अनुमति नहीं है। दो पतों का जोड़ किसी काम की जगह नहीं बताता, इसलिए p + q लिखते ही compiler त्रुटि देता है — invalid operands to binary +। pointer में कोई पूर्णांक जोड़ा जा सकता है, जैसे p + 1, और दो pointers को घटाया जा सकता है। पर pointer + pointer मना है। program बनता ही नहीं, इसलिए 2, 3 या 5 कुछ भी नहीं छपता।
C does not allow adding two pointers together. The sum of two addresses does not point to any meaningful place, so p + q makes the compiler stop with an error like invalid operands to binary +. You can add an integer to a pointer, as in p + 1, and you can subtract one pointer from another, but pointer plus pointer is not allowed. Since the program never builds, nothing like 2, 3 or 5 is printed.
प्रश्न 8उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf("%d\n", *ptr);
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf("%d\n", *ptr);
}
Ax का पताAddress of x
Bकचरा मान (Junk value)Junk value
C0
DRun time error
सही उत्तर / Answer: (C)
हल / Solution
यहाँ x = 0 है और ptr = &x, यानी ptr में x का पता है। printf में *ptr छापा जा रहा है। * उस पते पर जाकर वहाँ रखा मान देता है, जो x का मान 0 है। इसलिए आउटपुट 0 आता है। x का पता तब छपता जब ptr को %p से छापते। x पहले से initialize है, इसलिए कचरा मान नहीं आता। ptr एक वैध variable को point करता है, इसलिए run time error भी नहीं होता।
Here x is 0 and ptr = &x, so ptr holds the address of x. The printf prints *ptr. The * goes to that address and gives the value stored there, which is 0. So the output is 0. The address would print only if ptr itself were printed with %p. Since x is initialized, there is no junk value. Since ptr points to a valid variable, there is no run time error.
प्रश्न 9उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &5;
printf("%p\n", ptr);
}
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &5;
printf("%p\n", ptr);
}
A5
B5 का पताAddress of 5
Cकुछ नहींNothing
DCompile time error
सही उत्तर / Answer: (D)
हल / Solution
& operator सिर्फ़ उन्हीं चीज़ों पर लगता है जिनकी memory में जगह हो, जैसे variable। इन्हें lvalue कहते हैं। 5 एक constant है, इसकी अपनी कोई पता वाली जगह नहीं होती। इसलिए &5 लिखते ही compiler त्रुटि देता है — cannot take the address of an rvalue। program बनता ही नहीं, तो कुछ छपने का सवाल ही नहीं। इसलिए '5', '5 का पता' और 'कुछ नहीं' तीनों ग़लत हैं।
The & operator works only on things that have a place in memory, such as variables. These are called lvalues. The value 5 is a constant with no address of its own. So writing &5 makes the compiler stop with an error like cannot take the address of an rvalue. The program is never built, so nothing is printed at all. That is why 5, Address of 5 and Nothing are all wrong.
प्रश्न 10उत्तर + हल
C प्रोग्राम में पॉइंटर्स का उपयोग करने का कारण है
The reason for using pointers in a C program is
Aपॉइंटर्स अलग-अलग functions को अपने local variables साझा करने और बदलने देते हैंPointers allow different functions to share and modify their local variables
Bबड़े structure को पास करना, ताकि structure की पूरी नकल से बचा जा सकेTo pass large structures so that complete copy of the structure can be avoided
Cपॉइंटर्स linked list और binary tree जैसी जटिल linked data structures बनाना संभव करते हैंPointers enable complex linked data structures like linked lists and binary trees
Dउपरोक्त सभीAll of the above
सही उत्तर / Answer: (D)
हल / Solution
तीनों कारण सही हैं। पहला, किसी variable का पता दूसरे function को देने पर वह function उसी variable को बदल सकता है, जैसे swap(&a, &b) में। दूसरा, बड़ा structure पास करते समय पूरी नकल बनाने की जगह सिर्फ़ उसका पता भेजा जाता है। इससे समय और memory दोनों बचते हैं। तीसरा, linked list और tree में हर node अगले node का पता रखता है, जो pointer से ही संभव है। इसलिए उत्तर 'उपरोक्त सभी' है।
All three reasons are correct. First, passing the address of a variable lets another function change that same variable, as in swap(&a, &b). Second, when a large structure is passed, only its address is sent instead of making a full copy, which saves time and memory. Third, in linked lists and trees each node stores the address of the next node, which is only possible with pointers. So the answer is All of the above.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
निम्नलिखित प्रोग्राम कोड का आउटपुट क्या होगा? #include <stdio.h> void main() { int i=3, *j, **k; j = &i; k = &j; printf("%d%d%d", *j, **k, *(*k)); }
What will be the output of the following program code? #include <stdio.h> void main() { int i=3, *j, **k; j = &i; k = &j; printf("%d%d%d", *j, **k, *(*k)); }
इस C कोड का आउटपुट क्या है? int main() { int ary[4] = {1, 2, 3, 4}; int *p[4]; int i; for ( i = 0; i < 4; i++) { p[i] = &ary[i]; } printf("%d\n", *p[0]); return 0; }
What is the output of this C code? int main() { int ary[4] = {1, 2, 3, 4}; int *p[4]; int i; for ( i = 0; i < 4; i++) { p[i] = &ary[i]; } printf("%d\n", *p[0]); return 0; }