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

Functions Questions and Answers

42.

What is the output of this code having void return-type function?

void foo()
    {
        return 1;
    }

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

 

Answer: C

Correct answer: Compile time error

A void function must not return a value, so return 1; is an error - and assigning the result of a void function to an int is a second one. Either alone would stop the program compiling.

Please log in or register to report this question.

43.

The output of the code below is

int *m();
    void main()
    {
        int k = m();
        printf("%d", k);
    }
    int *m()
    {
        int a[2] = {5, 8};
        return a;
    }

 

Answer: D

Correct answer: Varies

Two faults compound each other. The function returns a pointer to a local array that no longer exists, and the caller assigns that pointer to an int. What is printed is an address reinterpreted as an integer - different on every run and every machine.

Please log in or register to report this question.

44.

Maximum number of arguments that a function can take is 12

Answer: B

Correct answer: No

The standard sets no limit of twelve. It requires an implementation to support at least 127 parameters, and most allow far more - so the practical limit is the compiler’s, not the language’s. (A function needing many parameters is usually better given a structure.)

Please log in or register to report this question.

45.

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.

46.

Functions cannot return more than one value at a time

Answer: A

Correct answer: True

A C function returns at most one value. Where more is needed the usual devices are to pass pointers for the extra results, or to return a structure containing them all.

Please log in or register to report this question.

47.

What linkage does automatic variables have?

Answer: C

Correct answer: No linkage

An automatic variable has no linkage: its name refers to a fresh object on each entry to the block and cannot be referred to from anywhere else - not from another file, not even from another function. Only file-scope names have linkage, internal or external.

Please log in or register to report this question.

48.

What is the output of this C code?

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

 

Answer: A

Correct answer: 4

The inner block contains an assignment, not a declaration, so it changes the x already in scope. The value printed is 4.

Please log in or register to report this question.

50.

What is the output of this C code?

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

 

Answer: A

Correct answer: 2

The declaration inside main - void foo(int) - is the one in scope at the call, so foo(1) matches it, and it agrees with the definition. The outer void foo() declares a function with an unspecified parameter list rather than none, so it does not conflict. The program prints 2.

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