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

Functions Questions and Answers

31.

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.

32.

If return type for a function is not specified, it defaults to int

Answer: A

Correct answer: True

Under the older rules an omitted return type defaulted to int - which is why so much old code writes main() rather than int main(). C99 removed the default, so a modern compiler will at least warn.

Please log in or register to report this question.

33.

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.

34.

Functions can be called either by value or reference

Answer: A

Correct answer: True

C passes everything by value, but passing a pointer by value gives the function the caller’s address and so the effect of call by reference. Both styles are therefore available, which is why arrays - whose names decay to pointers - behave as though passed by reference.

Please log in or register to report this question.

35.

A function may have any number of return statements each returning different values.

Answer: A

Correct answer: True

A function may contain as many return statements as its logic needs - typically one per branch - and each may return a different value. The first one reached ends the function.

Please log in or register to report this question.

36.

Names of functions in two different files linked together must be unique

Answer: A

Correct answer: True

Once two files are linked together they share a single global namespace, so two external functions with the same name collide and the linker reports a duplicate symbol. The way to avoid it is to declare a function static, which confines it to its own file.

Please log in or register to report this question.

37.

Functions cannot return a floating point number

Answer: B

Correct answer: No

A function may return any type it likes, floating point included - double sqrt(double) is the obvious example. The statement is false.

Please log in or register to report this question.

38.

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.

39.

If a function contains two return statements successively, the compiler will generate warnings. Yes/No ?

Answer: A

Correct answer: Yes

Two return statements one after the other make the second unreachable: the first ends the function. Compilers warn about unreachable code because it almost always means the author intended something else.

Please log in or register to report this question.

40.

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.

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