FliQi Education App Download
प्रश्न-बैंक · C Language

Function in C Language — प्रश्न और उत्तर

C Language · 97 जाँचे हुए (verified) प्रश्न

  • 97 जाँचे हुए प्रश्न
  • हिंदी + English

पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।

भाषा
प्रश्न 1उत्तर + हल
इस C कोड का आउटपुट क्या है?

#include<stdio.h>

int x = 5;

void main(){

    int x = 3;

    printf("%d", x);

    {

        int x = 4;

    }

    printf("%d", x);

}
What is the output of this C code?

#include<stdio.h>

int x = 5;

void main(){

    int x = 3;

    printf("%d", x);

    {

        int x = 4;

    }

    printf("%d", x);

}
  1. A3 3
  2. B3 4
  3. C3 5
  4. Dरन टाइम एररRun time error

सही उत्तर / Answer: (A)

हल / Solution
बाहर x का मान पाँच है, पर main के भीतर नया x बनता है जिसका मान तीन है और जो बाहर वाले को ढक देता है। पहला printf इसी भीतरी चर को देखता है, सो तीन छपता है। आगे के कोष्ठक-खंड में एक और x बनता है जिसका मान चार है, पर वह उसी खंड तक सीमित है और कोष्ठक बंद होते ही मिट जाता है। दूसरा printf फिर main वाले x को पढ़ता है, इसलिए दोबारा तीन आता है।
Outside, x has the value five, but inside main a new x with value three hides it. The first printf sees this inner variable, so it prints three. The block in braces that follows creates yet another x with value four, yet that variable lives only inside that block and dies as soon as the brace closes. The second printf therefore reads main's own x once more and prints three again.
प्रश्न 2उत्तर + हल
इस C कोड का आउटपुट क्या है?

#include<stdio.h>

int x;

void main(){

    printf("%d", x);

}
What is the output of this C code?

#include<stdio.h>

int x;

void main(){

    printf("%d", x);

}
  1. Aगार्बेजGarbage
  2. Bरन टाइम एररRun time error
  3. C0
  4. Dकुछ नहीं छपेगाPrint Nothing

सही उत्तर / Answer: (C)

हल / Solution
x हर फ़ंक्शन के बाहर घोषित है, यानी वह वैश्विक (global) चर है। मानक कहता है कि ऐसे चर, जिन्हें शुरू में कोई मान न दिया जाए, अपने-आप शून्य से भर दिए जाते हैं। वे प्रोग्राम चलने से पहले ही स्थिर भंडारण में बन जाते हैं। इसलिए printf शून्य छापता है। गार्बेज तब आता जब x किसी फ़ंक्शन के भीतर का चर होता। रन टाइम एरर की कोई वजह नहीं, और छपना भी होगा ही।
Here x is declared outside every function, so it is a global variable. The standard says that such variables, when no initial value is given, are set to zero automatically. They are created in static storage before the program even starts running. So printf prints zero. Garbage would appear only if x were a local variable inside some function. There is no reason at all for a run time error, and something certainly does get printed.
प्रश्न 3उत्तर + हल
इस C कोड का आउटपुट क्या है?

#include<stdio.h>

void main(){

    m();

    printf("%d", x);

}

int x;

void m(){

    x = 4;

}
What is the output of this C code?

#include<stdio.h>

void main(){

    m();

    printf("%d", x);

}

int x;

void m(){

    x = 4;

}
  1. A4
  2. Bकम्पाइल टाइम एररCompile time error
  3. C0
  4. DअपरिभाषितUndefined

सही उत्तर / Answer: (B)

हल / Solution
C में किसी नाम का इस्तेमाल करने से पहले उसकी घोषणा दिख जानी चाहिए। यहाँ x की घोषणा main के नीचे लिखी है, पर printf उसे main के भीतर पढ़ने की कोशिश करता है। उस जगह compiler को x का कोई पता नहीं, सो वह «x undeclared» कहकर रुक जाता है। m() की कॉल भी अपनी परिभाषा से ऊपर है, जिस पर चेतावनी मिलती है। प्रोग्राम बनता ही नहीं, इसलिए चार या शून्य छपने का सवाल नहीं।
In C a name must be declared before it is used. Here x is declared below main, but printf tries to read it inside main. At that point the compiler knows nothing about x, so it stops with an undeclared identifier error. The call to m() also sits above its own definition, which draws a warning of its own. Since the program never compiles, neither four nor zero can be printed.
प्रश्न 4उत्तर + हल
नीचे दिए गए कोड का आउटपुट क्या है?

#include<stdio.h>

enum m{JAN, FEB, MAR};

enum m foo();

int main(){

    enum m i = foo();

    printf("%d\n", i);

}

int  foo(){

    return JAN;

}
What is the output of the code given below?

#include<stdio.h>

enum m{JAN, FEB, MAR};

enum m foo();

int main(){

    enum m i = foo();

    printf("%d\n", i);

}

int  foo(){

    return JAN;

}
  1. Aकम्पाइल टाइम एररCompile time error
  2. B0
  3. CJAN
  4. D1

सही उत्तर / Answer: (A)

हल / Solution
पहले घोषणा की गई है enum m foo(); यानी foo का प्रतिफल प्रकार enum m है। नीचे उसी फ़ंक्शन की परिभाषा int लौटाने वाली लिखी गई है। C यहाँ enum प्रकार और int को एक ही नहीं मानता, इसलिए दोनों घोषणाएँ टकराती हैं और compiler «conflicting types» की त्रुटि देता है। JAN का मान शून्य होता, पर प्रोग्राम बनता ही नहीं, सो शून्य या JAN छपने का सवाल नहीं उठता। उत्तर कम्पाइल टाइम एरर है।
The program first declares enum m foo(); which promises that foo returns the enum type. Lower down the same function is defined as returning int. C does not treat an enum type and int as the same type here, so the two declarations conflict and the compiler reports a conflicting types error. The value of JAN would have been zero, but since the program never compiles, neither zero nor JAN can be printed.
प्रश्न 5उत्तर + हल
क्या C में फ़ंक्शन ऐनुमरेशन कांस्टेंट लौटा सकते हैं?
Can functions return enumeration constants in c?
  1. Aसत्यtrue
  2. Bअसत्यfalse
  3. Cकम्पाइलर पर निर्भरdepends on the compiler
  4. Dमानक पर निर्भरdepends on the standard

सही उत्तर / Answer: (A)

हल / Solution
C में ऐनुमरेशन कांस्टेंट पूर्णांक मान ही होते हैं, सो फ़ंक्शन उन्हें बिना किसी अड़चन लौटा सकता है। जैसे enum day {MON, TUE}; के बाद ऐसा फ़ंक्शन बनाया जा सकता है जो MON लौटाए। घोषित प्रतिफल प्रकार enum हो या सादा int, दोनों चलते हैं, क्योंकि enum किसी पूर्णांक प्रकार के अनुरूप होता है। यह बरताव मानक में तय है, इसलिए कम्पाइलर या मानक पर निर्भर वाले विकल्प ग़लत हैं। सो उत्तर सत्य है।
Enumeration constants in C are nothing but integer values, so a function can return them without any trouble. For example after enum day {MON, TUE}; one can write a function that simply returns MON. The declared return type may be the enum type or plain int, since an enum is compatible with some integer type. This behaviour is fixed by the standard, so the answers that depend on the compiler or on the standard are both wrong.
प्रश्न 6उत्तर + हल
इस C कोड का आउटपुट क्या है?

#include<stdio.h>

double foo();

int main(){

    foo();

    return 0;

}

foo(){

    printf("2 ");

    return 2;

}
What is the output of this C code?

#include<stdio.h>

double foo();

int main(){

    foo();

    return 0;

}

foo(){

    printf("2 ");

    return 2;

}
  1. A2
  2. Bकम्पाइल टाइम एररCompile time error
  3. Cकम्पाइलर पर निर्भरDepends on the compiler
  4. Dमानक पर निर्भरDepends on the standard

सही उत्तर / Answer: (B)

हल / Solution
ऊपर घोषणा है double foo(); यानी foo को double लौटाने वाला कहा गया है। नीचे परिभाषा में प्रतिफल का प्रकार लिखा ही नहीं, सो वह int लौटाने वाला फ़ंक्शन बनता है। एक ही नाम के दो प्रकार आपस में टकराते हैं, इसलिए compiler «conflicting types» कहकर रुक जाता है। यह टकराव हर मानक में त्रुटि है, सो कम्पाइलर या मानक पर निर्भर वाले विकल्प ग़लत हैं। दो भी नहीं छपेगा, क्योंकि प्रोग्राम बनता ही नहीं।
The declaration at the top says double foo(); so foo is promised to return a double. The definition below gives no return type at all, which makes it return int instead. The two declarations of the same name therefore conflict, and the compiler stops with a conflicting types message. This clash is an error under every standard, so the choices that depend on the compiler or on the standard are wrong, and two is never printed.
प्रश्न 7उत्तर + हल
नीचे दिए गए कोड का आउटपुट क्या है?

#include<stdio.h>

void m(int k){

    printf("hi");

}

void m(double k){

    printf("hello");

}

void main(){

    m(3);

}
The output of the code below is

#include<stdio.h>

void m(int k){

    printf("hi");

}

void m(double k){

    printf("hello");

}

void main(){

    m(3);

}
  1. Ahi
  2. Bhello
  3. Cकम्पाइल टाइम एररCompile time error
  4. Dकुछ नहींNothing

सही उत्तर / Answer: (C)

हल / Solution
C में एक ही फ़ंक्शन का नाम दोबारा इस्तेमाल नहीं हो सकता, क्योंकि यहाँ फ़ंक्शन ओवरलोडिंग (function overloading) होती ही नहीं। कोड में m नाम दो बार परिभाषित है, एक बार int लेकर और एक बार double लेकर, सो compiler इसे पुनर्परिभाषा मानकर त्रुटि देता है। यही कोड C++ में चल जाता, क्योंकि वहाँ प्राचल के प्रकार से फ़ंक्शन छाँटे जाते हैं। प्रोग्राम बनता ही नहीं, इसलिए hi या hello छपने का सवाल नहीं।
A function name cannot be reused in C, because the language has no function overloading at all. Here m is defined twice, once taking an int and once taking a double, so the compiler treats the second one as a redefinition and reports an error. The very same code would work in C++, where functions are picked by the types of their parameters. Since the program never compiles, neither hi nor hello can ever be printed.
प्रश्न 8उत्तर + हल
नीचे दिए कोड का आउटपुट क्या होगा?

#include<stdio.h>

int *m();

void main(){

    int *k = m();

    printf("%d", k);

}

int *m(){

    static int a[2] = {5, 8};

    return a;

}
Find the output of this C code.

#include<stdio.h>

int *m();

void main(){

    int *k = m();

    printf("%d", k);

}

int *m(){

    static int a[2] = {5, 8};

    return a;

}
  1. A5
  2. B8
  3. CपताAddress
  4. Dगार्बेजGarbage

सही उत्तर / Answer: (C)

हल / Solution
m() का प्रतिफल प्रकार int* है, यानी वह पता लौटाता है। भीतर a स्थायी (static) ऐरे है, सो फ़ंक्शन ख़त्म होने पर भी वह ज़िंदा रहता है। ऐरे का नाम लौटाने पर उसके पहले element का पता मिलता है, और k उसी पते को रखता है। इसलिए छपने पर पता दिखेगा, पाँच या आठ नहीं। गार्बेज भी नहीं आता, क्योंकि static भंडारण मिटता ही नहीं। ध्यान रखिए, पते के लिए सही विनिर्देशक %p है।
The return type of m() is int*, so the function hands back an address. Inside it, a is a static array, which means it stays alive even after the function ends. Returning the name of an array gives the address of its first element, and k stores that address. Printing k therefore shows an address, not five and not eight, and not garbage either, because static storage is never destroyed. Note that the proper specifier for an address is %p.
प्रश्न 9उत्तर + हल
आउटपुट ज्ञात करें?
#include<stdio.h>

int *m();

void main(){

    int *k = m();

    printf("%d", k[0]);

}

int *m(){

    static int a[2] = {5, 8};

    return a;

}
Find the output.
#include<stdio.h>

int *m();

void main(){

    int *k = m();

    printf("%d", k[0]);

}

int *m(){

    static int a[2] = {5, 8};

    return a;

}
  1. A5
  2. B8
  3. Cकुछ नहींNothing
  4. Dगार्बेजGarbage

सही उत्तर / Answer: (A)

हल / Solution
m() के अंदर array a static है। static variable function ख़त्म होने के बाद भी memory में बना रहता है, इसलिए उसका address लौटाना सुरक्षित है। m() array a के पहले element का address लौटाता है, जो pointer k में आ जाता है। k[0] यानी a[0] की value 5 है, इसलिए 5 छपता है। 8 तो a[1] है। अगर array static न होता, तो local array का address लौटाने से garbage मिल सकता था।
Inside m(), the array a is static. A static variable stays in memory even after the function ends, so returning its address is safe. m() returns the address of the first element of a, which is stored in the pointer k. k[0] means a[0], whose value is 5, so 5 is printed. 8 is a[1]. If the array were not static, returning a local array's address could give garbage.
प्रश्न 10उत्तर + हल
निम्नलिखित फ़ंक्शन द्वारा लौटाया गया डेटा प्रकार क्या होगा?
#include<stdio.h>

int func(){

    return (double)(char)5.0;

}
What will be the data type returned for the following function?
#include<stdio.h>

int func(){

    return (double)(char)5.0;

}
  1. Achar
  2. Bint
  3. Cdouble
  4. Dreturn में कई बार type-casting करना अवैध हैmultiple type-casting in return is illegal

सही उत्तर / Answer: (B)

हल / Solution
function जो value लौटाता है, उसका type हमेशा function के return type से तय होता है। यहाँ 5.0 पहले char में बदला, फिर double में। पर return होते समय वह int में बदल जाता है, क्योंकि func को int घोषित किया गया है। एक के बाद एक कई cast लगाना पूरी तरह वैध है, इसलिए चौथा विकल्प ग़लत है। लौटाया गया type int है, char या double नहीं।
The type of the value a function returns is always set by the function's declared return type. Here 5.0 is first cast to char and then to double, but at the return it is converted to int, because func is declared to return int. Applying several casts one after another is perfectly legal in C, so option four is wrong. The returned type is int, not char or double.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 11उत्तर app में
void रिटर्न-टाइप फ़ंक्शन वाले इस कोड का आउटपुट क्या है?
#include<stdio.h>

void foo(){

    return 1;

}

void main(){

    int x = 0;

    x = foo();

    printf("%d", x);

}
What is the output of this code having a void return-type function?
#include<stdio.h>

void foo(){

    return 1;

}

void main(){

    int x = 0;

    x = foo();

    printf("%d", x);

}
  1. A1
  2. B0
  3. Cरनटाइम एररRuntime error
  4. Dकंपाइल टाइम एररCompile time error
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 14उत्तर app में
निम्न में से कौन-सा फ़ंक्शन की घोषणा (declaration) का सही प्रारूप है?
Which of the following is a correct format for declaration of a function?
  1. Areturn-type function-name(argument type);
  2. Breturn-type function-name(argument type) {}
  3. Creturn-type (argument type)function-name;
  4. D(a) और (b) दोनोंBoth (a) and (b)
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 15उत्तर app में
इस C कोड का आउटपुट क्या है?
#include<stdio.h>

    void main()

    {

          void m();

        m();

    }

    void m()

    {

        printf("hi");

        m();

    }
What is the output of this C code?
#include<stdio.h>

    void main()

    {

          void m();

        m();

    }

    void m()

    {

        printf("hi");

        m();

    }
  1. Aकंपाइल टाइम एररCompile time error
  2. Bhi
  3. Cअनंत बार hiInfinite hi
  4. Dकुछ नहींNothing
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 16उत्तर app में
इस C कोड का आउटपुट क्या है?
#include<stdio.h>

void main(){

    m();

    void m(){

        printf("hi");

    }

}
What is the output of this C code?
#include<stdio.h>

void main(){

    m();

    void m(){

        printf("hi");

    }

}
  1. Ahi
  2. Bकंपाइल टाइम एररCompile time error
  3. Cकुछ नहींNothing
  4. Dबदलता रहता हैVaries
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
इस C कोड का आउटपुट क्या है?
#include<stdio.h>

void m(){

    printf("hi");

}

void main(){

    m();

}
What is the output of this C code?
#include<stdio.h>

void m(){

    printf("hi");

}

void main(){

    m();

}
  1. Ahi
  2. Bरन टाइम एररRun time error
  3. Cकुछ नहींNothing
  4. Dबदलता रहता हैVaries
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
इस C कोड का आउटपुट क्या है?
#include<stdio.h>

void foo();

int main(){

    void foo();

    foo();

    return 0;

}

void foo(){

    printf("2 ");

}
What is the output of this C code?
#include<stdio.h>

void foo();

int main(){

    void foo();

    foo();

    return 0;

}

void foo(){

    printf("2 ");

}
  1. Aकंपाइल टाइम एररCompile time error
  2. B2
  3. C2 2
  4. D2 2 2
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
इस C कोड का आउटपुट क्या है?
#include<stdio.h>

int main()

{

    void foo(), f();

    f();

}

void foo()

{

    printf("2 ");

}

void f()

{

    printf("1 ");

    foo();

}
What is the output of this C code?
#include<stdio.h>

int main()

{

    void foo(), f();

    f();

}

void foo()

{

    printf("2 ");

}

void f()

{

    printf("1 ");

    foo();

}
  1. Aकंपाइल टाइम एरर क्योंकि foo, main के लिए लोकल हैCompile time error as foo is local to main
  2. B1 2
  3. C2 1
  4. Dmain के अंदर फ़ंक्शन की घोषणा के कारण कंपाइल टाइम एररCompile time error due to declaration of functions inside main
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 21उत्तर app में
डिफ़ॉल्ट पैरामीटर पासिंग मैकेनिज़्म क्या है?
The default parameter passing mechanism is
  1. Aकॉल बाय वैल्यूCall by value
  2. Bकॉल बाय रेफ़रेंसCall by reference
  3. Cकॉल बाय वैल्यू रिज़ल्टCall by value result
  4. Dकोई नहींNone
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में
यदि फ़ंक्शन परिभाषा में रिटर्न टाइप नहीं लिखा गया हो, तो डिफ़ॉल्ट रिटर्न टाइप क्या होता है?
What is the default return type if it is not specified in the function definition?
  1. Avoid
  2. Bint
  3. Cfloat
  4. Dshort int
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 23उत्तर app में
किसी फ़ंक्शन से नियंत्रण वापस कॉलिंग/कॉलर फ़ंक्शन पर भेजने के लिए कौन-सा कीवर्ड प्रयोग होता है?
The keyword used to transfer control from a function back to the calling/caller function is
  1. Aswitch
  2. Bgoto
  3. Creturn
  4. Dexit
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 24उत्तर app में
जिस फ़ंक्शन का प्रोटोटाइप
int calculate(int num);
है, वह —
A function that is prototyped as
int calculate(int num);
may
  1. Amain() प्रोग्राम से num नाम के वेरिएबल में इन्टिजर वैल्यू प्राप्त कर सकता हैReceive an integer value in a variable named num from the main() program
  2. Bmain() प्रोग्राम से कोई भी इन्टिजर वैल्यू प्राप्त कर सकता हैReceive any integer value from the main() program
  3. C(a) और (b) दोनोंBoth (a) and (b)
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 25उत्तर app में
निम्नलिखित 'C' कोड में फ़ंक्शन किस क्रम में कॉल होंगे?
a = ( f1(23,14 ) * f2 (12/14)) + f3 () ;
In the following 'C' code, in which order would the functions be called?
a = ( f1(23,14 ) * f2 (12/14)) + f3 () ;
  1. Af1,f2,f3
  2. Bf3,f2,f1
  3. Cक्रम एक कंपाइलर से दूसरे कंपाइलर में बदल सकता हैThe order may vary from compiler to compiler
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 26उत्तर app में
C लैंग्वेज में फ़ंक्शन के प्रकार कौन-से हैं?
What are the types of functions in C language?
  1. Aलाइब्रेरी फ़ंक्शनLibrary function
  2. Bयूज़र डिफ़ाइंड फ़ंक्शनUser defined function
  3. CA और B दोनोंBoth A and B
  4. Dउपरोक्त में से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 28उत्तर app में
निम्नलिखित कोड के आउटपुट का अनुमान लगाएँ:

#include<stdio.h>

int main()

{

 

    void show()

    {

        printf("FliQi Education");

    }

    show();

    return 0;

}
Guess the output of the following code:

#include<stdio.h>

int main()

{

 

    void show()

    {

        printf("FliQi Education");

    }

    show();

    return 0;

}
  1. Aकंपाइल टाइम एररCompile time error
  2. BFliQi Education
  3. Cरन टाइम एररRun Time Error
  4. Dइनमें से कोई नहींNone of the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 29उत्तर app में
C में डिफ़ॉल्ट पैरामीटर पासिंग मैकेनिज़्म है
The default parameter passing mechanism is
  1. Aकॉल बाय वैल्यूcall by value
  2. Bकॉल बाय रेफ़रेंसcall by reference
  3. Cकॉल बाय वैल्यू रिज़ल्टcall by value result
  4. Dइनमें से कोई नहींNone of these
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 30उत्तर app में
फ़ंक्शन्स के बारे में असत्य कथन ज्ञात कीजिए।
Find the false statement about functions.
  1. Aकथनों (statements) के एक समूह को बार-बार लिखने से बचाता है।Helps to avoid repeating a set of statements many times.
  2. Bफ़ंक्शन के लिए कोई मान लौटाना अनिवार्य है।Returning a value is compulsory for a function.
  3. Cअलग-अलग प्रोग्रामों में एक ही कोड बार-बार लिखने से बचाता है।Helps to avoid repeated programming across programs.
  4. Dडिबगिंग का काम आसान बनाता है।Makes the debugging task easier.
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Function in C Language के सभी 97 प्रश्न — उत्तर, हल और अभ्यास

FliQi Question Bank app में topic-वार अभ्यास, कठिनाई-स्तर और आपकी प्रगति।

  • पहला test मुफ़्त
  • हिंदी + English
  • जाँचे हुए उत्तर और हल

यह topic किन परीक्षाओं में आता है

C Language के दूसरे topics

सभी topics