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

Functions Questions and Answers

81.

Which of the following is an external variable?

int func (int a)
    {
        int b;
        return b;
    }
    int main()
    {
        int c;
        func (c);
    }
    int d;

 

Answer: D

Correct answer: d

d is declared at file scope, so it is the external variable - even though it appears at the end of the file, which merely limits how much of the file can see it. a is a parameter, and b and c are locals; all three are automatic.

Please log in or register to report this question.

82.

What will be the output?

int main()
    {
        printf("%d", d++);
    }
    int d = 10;

 

Answer: D

Correct answer: Compile time error

d is declared after main, so at the point of use it is not in scope. Under C99 and later an undeclared identifier is an error; older compilers would have assumed int and then found the later definition consistent, but the modern answer is a compile error.

Please log in or register to report this question.

83.

What will be the output?

double var = 8;
    int main()
    {
        int var = 5;
        printf("%d", var);
    }

 

Answer: A

Correct answer: 5

The local int var = 5; shadows the file-scope double var = 8; throughout main, so %d is matched with an int and prints 5. Shadowing is legal - the two are different objects in different scopes.

Please log in or register to report this question.

84.

What is the output of this C code?

double i;
    int main()
    {
       printf("%g\n",i);
       return 0;
    }

 

Answer: A

Correct answer: 0.000000

A file-scope double is zero-initialised, so it holds 0.0. %g chooses the shorter of the fixed and exponential forms, and for zero the answer is 0 either way.

Please log in or register to report this question.

85.

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

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

 

Answer: B

Correct answer: Data segment

p is a file-scope variable with an explicit initialiser, so it goes in the data segment, which holds initialised statics and whose contents come from the executable file. (Strictly, a pointer initialised to NULL is all-zero and many toolchains put it in BSS after all; the distinction the question is drawing is between explicitly initialised and not.)

Please log in or register to report this question.

86.

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.

87.

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.

88.

Property of external variable to be accessed by any source file is called by C90 standard as:

Answer: A

Correct answer: external linkage

Linkage is the term for whether a name refers to the same object across translation units; scope is where a name is visible within one. A file-scope variable has external linkage - the same object however many files declare it.

Please log in or register to report this question.

90.

What is the output of this C code?

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

 

Answer: A

Correct answer: 9

x = 9; assigns to the file-scope static variable, and the inner block’s int x = 4; declares a different variable that vanishes at the closing brace. So the printf, back outside, shows 9.

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