Wednesday, 29 November 2017

C MCQ - Static Register and Automatic Variables

1. What is the output of this C code?

    #include <stdio.h>
    void main()
    {
        static int i;
        printf("i is %d", i);
    }
a) 0
b) 1
c) Garbage Value
d) Run time error

2. What is the output of this C code?

    #include <stdio.h>
    int *i;
    int main()
    {
        if (i == NULL)
            printf("true\n");
        return 0;
    }
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing

3. What is the output of this C code?


    #include <stdio.h>
    static int i;
    void main()
    {
        int i;
        printf("i is %d", i);
    }
a) 0
b) Garbage Value
c) Run time error
d) Nothing

4. What is the output of this C code?


    #include <stdio.h>

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

5. The scope of an automatic variable is:

a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears

6. Automatic variables are allocated space in the form of a:

a) stack
b) queue
c) priority queue
d) random

7. Which of the following is a storage specifier?

a) enum
b) union
c) auto
d) volatile

8. Automatic variables are stored in

a) stack
b) data segment
c) register
d) heap

9. What is the output of this C code?


    #include <stdio.h>
    int main()
    {
        register int i = 10;
        int *q = &i;
        *q = 11;
        printf("%d %d\n", i, *q);
    }
a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error

10. Register storage class can be specified to global variables

a) true
b) false
c) Depends on the compiler
d) Depends on the standard

11. Register variables reside in

a) stack
b) registers
c) heap
d) main memory

12. Which of the following operation is not possible in a register variable?

a) Reading the value into a register variable
b) Copy the value from a memory variable
c) Global declaration of register variable
d) All of the mentioned

No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...