पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int a;
printf("Enter number: ");
scanf("%5d", &a); //input 1234567
printf("%d", a);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
int a;
printf("Enter number: ");
scanf("%5d", &a); //input 1234567
printf("%d", a);
return 0;
}
A1234567
B12345
C123
D54321
सही उत्तर / Answer: (B)
हल / Solution
scanf में %5d जैसी चौड़ाई बताती है कि ज़्यादा से ज़्यादा कितने अक्षर पढ़े जाएँ। इनपुट 1234567 में से सिर्फ़ पहले 5 अंक, यानी 12345, a में जाते हैं। बचे हुए 67 input buffer में रह जाते हैं। इसलिए 'Enter number:' संदेश के बाद printf 12345 छापता है। पूरा 1234567 सिर्फ़ सादे %d से पढ़ा जाता। 123 और 54321 का कोई आधार नहीं — scanf न 3 अंक पढ़ता है, न उन्हें उलटता है।
In scanf, a width like %5d limits how many characters are read. From the input 1234567, only the first 5 digits, 12345, are read into a. The remaining 67 stays in the input buffer. So after the prompt Enter number:, printf prints 12345. The full 1234567 would be read only with plain %d. 123 and 54321 have no basis: scanf neither reads 3 digits here nor reverses them.
प्रश्न 2उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char str[10];
int x;
scanf("%d:%4s",&x,str);// Enter 10:FliQi as input
printf("%d : %s",x, str);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char str[10];
int x;
scanf("%d:%4s",&x,str);// Enter 10:FliQi as input
printf("%d : %s",x, str);
return 0;
}
A10 : FliQi
B10 : FliQ
C0 : FliQi
DGarbage: FliQ
सही उत्तर / Answer: (B)
हल / Solution
फ़ॉर्मेट "%d:%4s" के तीन हिस्से हैं। %d से x में 10 जाता है। फ़ॉर्मेट का colon इनपुट के colon से मिलता है, इसलिए वह छोड़ दिया जाता है। फिर %4s ज़्यादा से ज़्यादा 4 अक्षर पढ़ता है, इसलिए str में FliQ जाता है और आख़िरी i buffer में रह जाता है। printf से 10 : FliQ छपता है। FliQi के लिए चौड़ाई 4 नहीं होनी चाहिए, और x सही पढ़ा गया, इसलिए 0 या garbage ग़लत है।
The format "%d:%4s" has three parts. %d reads 10 into x. The colon in the format must match the colon in the input, so it is skipped. Then %4s reads at most 4 characters, so str gets FliQ and the last i stays in the buffer. printf("%d : %s") prints 10 : FliQ. FliQi would need %s without width 4, and x is read correctly, so 0 or garbage is wrong.
प्रश्न 3उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char ch=65;
printf("%c\n", ch);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char ch=65;
printf("%c\n", ch);
return 0;
}
A65
BA
CCompile Time Error
Da
सही उत्तर / Answer: (B)
हल / Solution
char वेरिएबल असल में एक छोटा पूर्णांक रखता है, इसलिए char ch = 65 बिलकुल सही है, कोई compile error नहीं। 65 बड़े अक्षर A का ASCII कोड है। %c मान को अक्षर के रूप में छापता है, इसलिए आउटपुट A है और फिर नई पंक्ति आती है। 65 देखना हो तो %d लगाना पड़ता। छोटे a का कोड 97 है, वह 65 से नहीं बन सकता। मान कैसे दिखे, यह specifier तय करता है।
A char variable holds a small integer, so char ch = 65 is valid and gives no compile error. The value 65 is the ASCII code of the capital letter A. The %c specifier prints the value as a character, so the output is A, followed by a new line. The number 65 would appear with %d. Small a has code 97, so it cannot come from 65. The specifier decides how the value looks.
प्रश्न 4उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is 97
printf("%d\n", ch-32);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is 97
printf("%d\n", ch-32);
return 0;
}
A65
BA
C25
Da
सही उत्तर / Answer: (C)
हल / Solution
%c एक ही अक्षर पढ़ता है, इसलिए इनपुट 97 में से ch में सिर्फ़ '9' जाता है। '9' का ASCII कोड 57 है, क्योंकि '0' का कोड 48 है और '9' = 48 + 9। ch - 32 से 57 - 32 = 25 मिलता है, और %d उसे 25 छापता है। 65 वाला विकल्प मानता है कि पूरी संख्या 97 पढ़ी गई, जो %c कभी नहीं करता। A या a छपने के लिए printf में %c चाहिए था।
%c reads a single character, so from the input 97 scanf stores only '9' in ch. The ASCII code of '9' is 57, since '0' is 48 and '9' is 48 + 9. The expression ch - 32 gives 57 - 32 = 25, and %d prints it as 25. The option 65 assumes the whole number 97 was read, which %c never does. A and a would need %c in printf.
प्रश्न 5उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is 65
printf("%d\n", ch);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is 65
printf("%d\n", ch);
return 0;
}
A65
BA
C54
D6
सही उत्तर / Answer: (C)
हल / Solution
%c सिर्फ़ एक अक्षर पढ़ता है, इसलिए इनपुट 65 में से scanf केवल अक्षर '6' लेता है। '5' buffer में रह जाता है। अक्षर '6' का ASCII कोड 54 है, क्योंकि '0' का कोड 48 है और '6' = 48 + 6। printf का %d ch का अंकीय कोड छापता है, इसलिए आउटपुट 54 है। 65 या A तभी आते जब पूरी संख्या पढ़ी जाती, और 6 छपने के लिए printf में %c चाहिए था।
%c reads only one character, so from the input 65 scanf takes just the character '6'. The '5' stays in the buffer. The character '6' has ASCII code 54, because '0' is 48 and '6' is 48 + 6. printf with %d prints the numeric code of ch, so the output is 54. 65 and A would need scanf to read the whole number, and 6 would need %c in printf.
प्रश्न 6उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is A
printf("%c\n", ch);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch); // input is A
printf("%c\n", ch);
return 0;
}
A65
BA
C97
Da
सही उत्तर / Answer: (B)
हल / Solution
scanf का %c इनपुट से ठीक एक अक्षर पढ़ता है। उपयोगकर्ता A टाइप करता है, इसलिए ch में अक्षर 'A' जाता है, जिसका ASCII मान 65 है। printf का %c उसी मान को अक्षर के रूप में छापता है, इसलिए आउटपुट A है और फिर नई पंक्ति आती है। 65 तभी छपता जब %d लगाया जाता। 97 छोटे a का कोड है, और यहाँ अक्षर का case कहीं नहीं बदलता।
scanf with %c reads exactly one character from the input. The user types A, so ch stores the character 'A', whose ASCII value is 65. printf with %c prints the stored value as a character, so the output is A, followed by a new line. The number 65 would appear only with %d. 97 is the ASCII code of small a, and nothing here changes the letter case.
प्रश्न 7उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char str[20];
scanf("%s", str); // input is FliQi Education
printf("%s\n", str);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char str[20];
scanf("%s", str); // input is FliQi Education
printf("%s\n", str);
return 0;
}
AFliQi
BFliQi Education
CEducation
DPrint Nothing
सही उत्तर / Answer: (A)
हल / Solution
scanf का %s पहली whitespace — यानी space, tab या नई पंक्ति — आने तक ही अक्षर पढ़ता है। इनपुट FliQi Education है, इसलिए str में सिर्फ़ FliQi जाता है और अंत में '\0' जुड़ता है। Education शब्द input buffer में बिना पढ़े रह जाता है। फिर printf FliQi और नई पंक्ति छापता है। space समेत पूरी पंक्ति पढ़नी हो तो scanf के %s की जगह fgets() लगाया जाता है।
scanf with %s reads characters only up to the first whitespace, like a space, tab or new line. The input is FliQi Education, so scanf stores only FliQi in str and adds '\0' at the end. The word Education stays unread in the input buffer. printf then prints FliQi and a new line. To read the whole line with spaces, you would use fgets() instead of scanf with %s.
प्रश्न 8उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int a = 0;
scanf("%i", &a); // input is 010
printf("%d ", a);
scanf("%i", &a); //input is 0xf
printf("%d", a);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
int a = 0;
scanf("%i", &a); // input is 010
printf("%d ", a);
scanf("%i", &a); //input is 0xf
printf("%d", a);
return 0;
}
A10 15
B10 f
C8 15
D8 f
सही उत्तर / Answer: (C)
हल / Solution
scanf में %i संख्या को उसके आगे लगे prefix के आधार पर पढ़ता है। इनपुट 010 शून्य से शुरू होता है, इसलिए उसे octal माना जाता है — 1×8 + 0 = 8। इनपुट 0xf, 0x से शुरू होता है, इसलिए hexadecimal है — f = 15। printf का %d दोनों मानों को दशमलव में छापता है, इसलिए आउटपुट 8 15 है। scanf में %d होता तो 010 से 10 मिलता। printf का %d कभी अक्षर f नहीं छापता।
%i in scanf reads the number in the base shown by its prefix. Input 010 starts with 0, so it is read as octal: 1×8 + 0 = 8. Input 0xf starts with 0x, so it is read as hexadecimal: f = 15. printf with %d shows both values in decimal, so the output is 8 15. With %d in scanf, 010 would give 10. printf with %d never prints the letter f.
प्रश्न 9उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
char name[] = "FliQi Education";
printf("%s\n", name);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
char name[] = "FliQi Education";
printf("%s\n", name);
return 0;
}
AF
BFliQi Education
CFliQi
DEducation
सही उत्तर / Answer: (B)
हल / Solution
name ऐरे में string "FliQi Education" रखी है, और compiler उसके अंत में null अक्षर '\0' जोड़ देता है। %s दिए गए पते से अक्षर छापना शुरू करता है और '\0' मिलने तक छापता रहता है। printf बीच की space पर नहीं रुकता, इसलिए दोनों शब्द छपते हैं और फिर नई पंक्ति आती है। आउटपुट FliQi Education है। space पर रुकना सिर्फ़ scanf के %s में होता है। अकेला F छापने के लिए name[0] के साथ %c चाहिए।
The array name stores the string "FliQi Education", and the compiler adds a null character '\0' at the end. %s prints characters starting from the given address until it reaches '\0'. printf does not stop at the space, so both words are printed, followed by a new line. The output is FliQi Education. Only scanf with %s stops at a space. F alone would need %c with name[0].
प्रश्न 10उत्तर + हल
निम्नलिखित स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int a = 100;
printf("%o\n", a);
return 0;
}
What will be the output of the following snippet?
#include <stdio.h>
int main()
{
int a = 100;
printf("%o\n", a);
return 0;
}
A100
B144
C80
DCompile Time Error
सही उत्तर / Answer: (B)
हल / Solution
%o पूर्णांक को octal, यानी आधार 8 में छापता है। 100 को बदलिए: 100 ÷ 8 = 12, शेष 4; फिर 12 ÷ 8 = 1, शेष 4; फिर 1 ÷ 8 = 0, शेष 1। शेषफल नीचे से ऊपर पढ़ने पर 144 बनता है। जाँच: 1×64 + 4×8 + 4 = 100। इसलिए आउटपुट 144 है। 100 तो %d से छपता, 80 का octal से कोई संबंध नहीं, और कोड में कोई compile error भी नहीं है।
%o prints an integer in octal, that is, base 8. To convert 100: 100 ÷ 8 = 12 remainder 4, then 12 ÷ 8 = 1 remainder 4, then 1 ÷ 8 = 0 remainder 1. Reading the remainders from bottom to top gives 144. Check: 1×64 + 4×8 + 4 = 100. So the output is 144. 100 would come from %d, 80 has no link with octal 100, and the code has no compile error.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
एक मान्य C प्रारूप विनिर्देशक (format specifier) चुनें:
Choose a valid C format specifier:
A%d पूर्णांक स्थिरांक प्रिंट करता है%d prints integer constants
B%u अहस्ताक्षरित (unsigned) पूर्णांक स्थिरांक प्रिंट करता है%u prints unsigned integer constants
C%ld हस्ताक्षरित (signed) long और %lu अहस्ताक्षरित (unsigned) long स्थिरांक प्रिंट करता है%ld prints signed long and %lu prints unsigned long constants
C लैंग्वेज में प्रारूप विनिर्देशक (format specifier) क्या है?
What is a format specifier in C language?
Aप्रारूप विनिर्देशक संकलक को बताता है कि किसी वेरिएबल के मान को पहले से तय तरीक़े से बरता जाए।A format specifier tells compiler to treat a variable value in predefined way.
Bअलग-अलग प्रकार के डेटा को प्रिंट करने के लिए अलग-अलग प्रारूप विनिर्देशक लगते हैं।Different format specifiers are used to print different type of data.
Cफ़ॉर्मेट स्पेसिफ़ायर से फ़ाइलों में डेटा को तय प्रारूप में लिखा जाता है।Format specifiers are used to write data to files in a formatted way.