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

Functions Questions and Answers

31.

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.

32.

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.

33.

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.

34.

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.

35.

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.

36.

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.

37.

Can variable i be accessed by functions in another source file?

int i;
    int main()
    {
        printf("%d\n", i);
    }

 

Answer: D

Correct answer: true

A variable at file scope has external linkage by default, so another source file can reach it by declaring extern int i;. Adding static to the definition is what would prevent that.

Please log in or register to report this question.

38.

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.

Answer: C

Correct answer: All of the mentioned

All three are true of a static local variable. It keeps its value between calls, because it is initialised once and its storage lasts as long as the program; it therefore still exists after the function returns; and although its name is local, its address can be passed to another function, which may then modify it through the pointer.

Please log in or register to report this question.

40.

What is the notation for the following functions?

1.  int f(int a, float b)
    {
        /* Some code */
    }

2.  int f(a, b)
    int a; float b;
    {
        /* Some code */
    }

 

Answer: C

Correct answer: 1. ANSI Notation 2. KR Notation

The first form declares each parameter’s type inside the parentheses - the ANSI (prototype) style, introduced by the 1989 standard. The second lists only the names in the parentheses and declares their types between the parentheses and the body - the old Kernighan and Ritchie style. The ANSI form matters because it lets the compiler check the arguments at every call; the K&R form does not, and is now obsolete.

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