Machine-translated by Google. Questions are authored in English.
Top

Functions Questions and Answers

61.

Is it true that too many recursive calls may result into stack overflow?

Answer: A

Yes, too many recursive calls may result into stack overflow. because when a function is called its return address is stored in stack.

After sometime the stack memory will be filled completely. Hence stack overflow error will occur.

Please log in or register to report this question.

62.

What is the output of this C code?

int x = 5;
    void main()
    {
        int x = 3;
        printf("%d", x);
        {
            x = 4;
        }
        printf("%d", x);
    }

 

Answer: D

Correct answer: 3 4

The inner x = 4; is an assignment, not a declaration, so it changes the x already in scope - main's local. The first printf shows 3 and the second, after the block, shows 4. The file-scope x = 5 is shadowed throughout and never seen.

Please log in or register to report this question.

63.

 

What is the output of this C code?

void main()
    {
        m();
        m();
    }
    void m()
    {
        static int x = 5;
        x++;
        printf("%d", x);
    }

 

Answer: A

Correct answer: 6 7

A static local is initialised once, before the program starts, and keeps its value between calls - its storage lasts as long as the program even though its name is local. So the first call prints 6 and the second 7. An ordinary local would print 6 both times.

Please log in or register to report this question.

64.

The output of the code below is

void m(int k)
    {
        printf("hi");
    }
    void m(double k)
    {
        printf("hello");
    }
    void main()
    {
        m(3);
    }

 

Answer: C

Correct answer: Compile time error

C has no function overloading: two functions cannot share a name, whatever their parameters. The compiler reports a redefinition. In C++ this would compile, and m(3) would select the int version.

Please log in or register to report this question.

Answer: B

Correct answer: int sum(int a, int b) {return (a + b);}

A function definition must have its body in braces. The forms without braces are not definitions at all. (The third also uses the old K&R parameter style but omits the type declarations that style requires.)

Please log in or register to report this question.

67.

A function may have any number of return statements each returning different values.

Answer: A

Correct answer: True

A function may contain as many return statements as its logic needs - typically one per branch - and each may return a different value. The first one reached ends the function.

Please log in or register to report this question.

68.

Which of the following is a storage specifier?

Answer: C

Correct answer: auto

The storage class specifiers are auto, register, static, extern and typedef. enum and union introduce types, and volatile is a type qualifier, not a storage class.

Please log in or register to report this question.

69.

In C, a global variable that is not explicitly initialised is set to ________.

Answer: D

Correct answer: zero

Variables with static storage duration, which includes all globals, are zero-initialised before the program starts. It is local variables of automatic storage duration that hold indeterminate values until assigned.

Please log in or register to report this question.

70.

The output of the code below is

void main()
    {
        int k = m();
        printf("%d", k);
    }

    void m()
    {

        printf("hello");
    }

 

Answer: A

Correct answer: Error

m is defined after main and not declared before it, so at the call the compiler either rejects it outright or, under the old rules, assumes int m() - and the later definition as void m() then conflicts with that assumption. Either way the program does not compile. Assigning the result of a void function to an int would be an error in its own right.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Functions Questions and Answers || Functions MCQ Questions and Answers || Functions GK Questions and Answers || Functions GK MCQ Questions || Functions Multiple Choice Questions and Answers || Functions GK || GK on Functions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming