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

Functions Questions and Answers

101.

Property of external variable to be accessed by any source file is called by C90 standard as:

Answer: A

Correct answer: external linkage

Linkage is the term for whether a name refers to the same object across translation units; scope is where a name is visible within one. A file-scope variable has external linkage - the same object however many files declare it.

Please log in or register to report this question.

102.

What is the output of this C code?

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

 

Answer: C

Correct answer: Infinite hi

m calls itself as its last action, with no condition to stop it - unbounded recursion. It prints hi each time, so the output repeats until the stack is exhausted and the program crashes.

Please log in or register to report this question.

103.

Which part of the program address space is p stored in the code given below?

int *p = NULL;
    int main()
    {
        int i = 0;
        p = &i;
        return 0;
    }

 

Answer: B

Correct answer: Data segment

p is a file-scope variable with an explicit initialiser, so it goes in the data segment, which holds initialised statics and whose contents come from the executable file. (Strictly, a pointer initialised to NULL is all-zero and many toolchains put it in BSS after all; the distinction the question is drawing is between explicitly initialised and not.)

Please log in or register to report this question.

104.

What is the output of this C code?

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

 

Answer: D

Correct answer: 0

A variable at file scope has static storage duration, and every such object is zero-initialised before the program starts - it is not left holding junk, as an uninitialised automatic variable would be. So the value printed is 0.

Please log in or register to report this question.

105.

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.

106.

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.

107.

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