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

Functions Questions and Answers

111.

Which of the following is an external variable?

int func (int a)
    {
        int b;
        return b;
    }
    int main()
    {
        int c;
        func (c);
    }
    int d;

 

Answer: D

Correct answer: d

d is declared at file scope, so it is the external variable - even though it appears at the end of the file, which merely limits how much of the file can see it. a is a parameter, and b and c are locals; all three are automatic.

Please log in or register to report this question.

112.

What is the output of this C code?

void main()
    {
        m();
        void m()
        {
            printf("hi");
        }
    }

 

Answer: B

Correct answer: Compile time error

m is defined inside main, which standard C forbids - and it is also called before its definition is reached. The compiler rejects the program.

Please log in or register to report this question.

113.

What is the output of this C code?

void foo();
int main()
{
void foo(int);
foo();
return 0;
}
void foo()
{
printf("2 ");
}

 

Answer: B

Correct answer: Compile time error

Here the two disagree. The declaration in scope says void foo(int), so foo() is called with too few arguments; and the definition, void foo(), conflicts with it as well. Either fault alone is enough for the compiler to reject the program.

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.

Answer: C

Correct answer: Yes, but we call the function again to get the value, not as convenient as in using variable

C does allow it: a parameter written as a function is adjusted to a pointer to that function, so void wow(int func()) means void wow(int (*func)()). But what is passed is the function itself, not a value - so inside wow you must call it to obtain anything, which is less convenient than passing the value. This is the mechanism behind callbacks, such as the comparison function given to qsort.

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