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

Functions Questions and Answers

22.

The value computed in a function is given back to the caller using the ________ keyword.

Answer: A

Correct answer: return

return both ends the function and passes the value back. static, new and volatile have nothing to do with it - and new is not even a C keyword.

Please log in or register to report this question.

Answer: D

Correct answer: All of the mentioned

C has no function overloading: one name may denote only one function in a translation unit. So none of the three variations is allowed - not a different signature, not a different return type, not a different number of parameters. (C++ permits overloading on the parameters, though still not on the return type alone.)

Please log in or register to report this question.

24.

Array sizes are optional during array declaration by using ______ keyword.

Answer: C

Correct answer: extern

An extern declaration says the array is defined elsewhere, so its size may be omitted: extern int a[];. The definition in the other file supplies the size. Note the consequence - sizeof cannot be applied to it in this file, since the compiler does not know how big it is.

Please log in or register to report this question.

25.

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.

26.

In C all functions except main() can be called recursively.

Answer: B

Correct answer: False

main can be called recursively in C - it is an ordinary function in that respect, and the standard permits it. (C++ forbids it.) So the statement that every function except main may recurse is false.

Please log in or register to report this question.

27.

What is the output of this C code?

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

 

Answer: A

Correct answer: hi

m is defined before main, so it is already declared when the call is reached, and it simply prints hi. (void main() is non-standard, but every compiler accepts it.)

Please log in or register to report this question.

28.

What is the output of this C code?

int main()
    {
        auto i = 10;
        const auto int *p = &i;
        printf("%d\n", i);
    }

 

Answer: A

Correct answer: 10

auto i = 10; relies on the old implicit int, and const auto int *p combines a qualifier with a storage class, which is allowed. The program prints 10 - though a modern compiler will warn, since C99 removed implicit int.

Please log in or register to report this question.

29.

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

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

 

Answer: C

Correct answer: Bss segment

p is at file scope with no initialiser, so it belongs in BSS - the block reserved for zero-initialised statics. BSS occupies no space in the executable file: only its size is recorded, and the loader zeroes it, which is why an uninitialised global costs nothing on disk.

Please log in or register to report this question.

30.

Every function must return a value

Answer: B

Correct answer: No

A function declared void returns nothing at all, and needs no return statement - reaching the closing brace ends it. Only a function with a non-void return type is obliged to return a value.

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