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

Functions Questions and Answers

91.

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.

92.

What is the output of this C code?

void main()
    {
        static int x;
        printf("x is %d", x);
    }

 

Answer: D

Correct answer: 0

A static variable, whether at file scope or inside a function, is zero-initialised if given no initialiser. So it prints 0 - unlike an ordinary automatic variable, which would hold junk.

Please log in or register to report this question.

93.

What is the output of this C code?

static int x;
    void main()
    {
        int x;
        printf("x is %d", x);
    }

 

Answer: A

Correct answer: Junk value

The local int x; shadows the file-scope static, and being an automatic variable with no initialiser it holds whatever was on the stack - a junk value. Only variables with static storage duration are zeroed for you.

Please log in or register to report this question.

Answer: C

Correct answer: static static int a; //a static variable prefixed with static

A storage class specifier may appear only once in a declaration, so static static is rejected. The other two are legal: static a = 10; relies on the old implicit int, and static int func(int); declares a function with internal linkage.

Please log in or register to report this question.

95.

Which of the following cannot be static in C?

Answer: D

Correct answer: None of the mentioned

Variables and functions can both be static, which gives them internal linkage or, for a local variable, a lifetime as long as the program’s. A structure variable can be static too. What cannot be static is a structure type - but a type has no storage class in the first place.

Please log in or register to report this question.

Answer: D

Correct answer: Both (a) and (b)

An automatic variable is visible from its declaration to the end of the block that contains it, and that includes any blocks nested inside - unless one of them declares another variable of the same name, which shadows it.

Please log in or register to report this question.

97.

Automatic variables are allocated space in the form of a:

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.

98.

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.

100.

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