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

Functions Questions and Answers

72.

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.

73.

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.

74.

What are automatic variables initialised to?

Answer: A

Correct answer: Junk value

An automatic variable is not initialised: it holds whatever bytes were left on the stack by earlier calls. Reading one before assigning to it is undefined behaviour, and the value is unpredictable - which is why compilers warn about it.

Please log in or register to report this question.

75.

In a function two return statements should never occur.

Answer: B

Correct answer: No

Several return statements in one function are perfectly ordinary - one per branch is the common pattern, and it often reads better than forcing a single exit. What should not happen is two consecutive returns, since the second can never be reached.

Please log in or register to report this question.

76.

What will be the output?

double var = 8;
    int main()
    {
        int var = 5;
        printf("%d", var);
    }

 

Answer: A

Correct answer: 5

The local int var = 5; shadows the file-scope double var = 8; throughout main, so %d is matched with an int and prints 5. Shadowing is legal - the two are different objects in different scopes.

Please log in or register to report this question.

Answer: D

Correct answer: Both (a) & (b)

Both statements describe the same property from two sides: an automatic variable exists only within its block, and it ceases to exist when the block is left. Its storage on the stack is reclaimed at once, which is why returning a pointer to one is a bug.

Please log in or register to report this question.

78.

Where are automatic variables allocated memory?

Answer: D

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.

79.

What is the output of this C code?

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

 

Answer: A

Correct answer: 9

x = 9; assigns to the file-scope static variable, and the inner block’s int x = 4; declares a different variable that vanishes at the closing brace. So the printf, back outside, shows 9.

Please log in or register to report this question.

Loading…
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