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

Functions Questions and Answers

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.

72.

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.

73.

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.

74.

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.

75.

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.

76.

Usually recursion works slower than loops.

Answer: A

When a recursive call is made, the function/process clones itself and then process that funtion. This leads to time and space constrains.

In a loop, there is no recursive call involved that saves a lot of time and space too.

Please log in or register to report this question.

77.

What is the output of this C code?

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

 

Answer: B

Correct answer: Compile time error

x is declared after main, so it is not in scope where main uses it, and m is neither declared nor defined before its call. The compiler rejects the program on both counts.

Please log in or register to report this question.

79.

If a function contains two return statements successively, the compiler will generate warnings. Yes/No ?

Answer: A

Correct answer: Yes

Two return statements one after the other make the second unreachable: the first ends the function. Compilers warn about unreachable code because it almost always means the author intended something else.

Please log in or register to report this question.

80.

Automatic variables are stored in:

Answer: A

Correct answer: stack

Automatic variables are allocated on the stack: space is reserved when the block is entered and released when it is left, which is what makes their lifetime match the block and what makes recursion possible - each call gets its own frame.

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