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

Functions Questions and Answers

21.

Is an assignment statement that gives a value to a local static variable executed only once?

Answer: B

Correct answer: false

The initialisation of a static variable happens once, before the program starts. But an ordinary assignment to it inside the function is an executable statement like any other, and runs every time the function is called - which would defeat the whole point of making the variable static.

Please log in or register to report this question.

Answer: A

Correct answer: return-type function-name(argument type);

A declaration (prototype) states the return type, the name and the parameter types, and ends with a semicolon - no body. Adding a body makes it a definition, which is a different thing.

Please log in or register to report this question.

23.

What is the output of this C code?

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

 

Answer: B

Correct answer: 2

The function is declared at file scope and again inside main. Repeating a declaration is harmless as long as the two agree, which they do, so the program compiles and prints 2.

Please log in or register to report this question.

24.

Which of the following storage classes supports the char data type?

Answer: D

Correct answer: All of the mentioned

char works with every storage class: auto char, static char and register char are all valid. Storage class and type are independent choices - the first says where and how long the object lives, the second what it holds.

Please log in or register to report this question.

25.

What is the output of this C code?

int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}

 

Answer: B

Correct answer: 1 2

Declaring void foo(), f(); inside main is legal - it declares them, without defining them, and the declaration is simply local in scope. f() is then called; it prints 1 and calls foo, which prints 2. Output: 1 2.

Please log in or register to report this question.

26.

What is the format identifier for “static a = 20.5;”?

Answer: B

Correct answer: %d

With no type given, static a = 20.5; falls back on the old implicit int, so the value is truncated to 20 and the correct specifier is %d. The declaration is legal only under the pre-C99 rules; a modern compiler will warn or reject it.

Please log in or register to report this question.

28.

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.

30.

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.

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