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

Functions Questions and Answers

Answer: D

Correct answer: From the point of declaration to the end of the file being compiled

Scope runs from the point of declaration to the end of the file - a variable declared at the bottom of a file is not visible to functions above it. Being reachable from other files is a matter of linkage, which is a different property; an extern declaration in the other file is what brings it into scope there.

Please log in or register to report this question.

Answer: D

Correct answer: From the point of declaration to the end of the file being compiled

A function’s name is in scope from its declaration to the end of the file - which is exactly why prototypes are put at the top or in a header. Its linkage is external, so other files can call it once they have declared it.

Please log in or register to report this question.

64.

What is the output of the following program?

#include <stdio.h>

void swap(int m, int n)
{
   int x = m;
   
   m = n;
   n = x;
}
main()
{
   int x=5, y=3;

   swap(x,y);
   printf("%d %d", x, y);
}

 

Answer: B

Correct answer: 5 3

C passes arguments by value, so swap receives copies and exchanges the copies. The originals in main are untouched, and the output is 5 3. To swap the caller’s variables the function must take pointers and be called as swap(&x, &y).

Please log in or register to report this question.

65.

The variable declaration with no storage class specified is by default:

Answer: A

Correct answer: auto

With no storage class specified, a variable declared inside a block is auto. (At file scope the default is different: external linkage and static storage duration.)

Please log in or register to report this question.

66.

Can a function return a structure in C?

Answer: A

Correct answer: true

A function may return a structure, and the whole structure is copied back to the caller. It is the standard way of returning several values at once - and it is why the language does not need multiple return values. Returning a large structure copies a good deal of data, so a pointer is often preferred for big ones.

Please log in or register to report this question.

67.

Is it true that too many recursive calls may result into stack overflow?

Answer: A

Yes, too many recursive calls may result into stack overflow. because when a function is called its return address is stored in stack.

After sometime the stack memory will be filled completely. Hence stack overflow error will occur.

Please log in or register to report this question.

68.

What is the output of this C code?

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

 

Answer: D

Correct answer: 3 4

The inner x = 4; is an assignment, not a declaration, so it changes the x already in scope - main's local. The first printf shows 3 and the second, after the block, shows 4. The file-scope x = 5 is shadowed throughout and never seen.

Please log in or register to report this question.

69.

 

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.

70.

The output of the code below is

void m(int k)
    {
        printf("hi");
    }
    void m(double k)
    {
        printf("hello");
    }
    void main()
    {
        m(3);
    }

 

Answer: C

Correct answer: Compile time error

C has no function overloading: two functions cannot share a name, whatever their parameters. The compiler reports a redefinition. In C++ this would compile, and m(3) would select the int version.

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