Fundamentals Of Data Structure MCQ'S SET-4

 




1] Which is an indirection operator among the following?

a) &

b) *

c) ->

d) . 

ANSWER:  B


2] Which of the following does not initialize ptr to null (assuming variable declaration of a as int     a=0;?

a) int *ptr = &a;

b) int *ptr = &a – &a;

c) int *ptr = a – a;

d) All of the mentioned

ANSWER:  A


3] What is the output of this C code?

    #include <stdio.h>

    int x = 0;

    void main()

    {

        int *ptr = &x;

        printf("%p\n", ptr);

        x++;

        printf("%p\n ", ptr);

    }


a) Same address

b) Different address

c) Compile time error

d) Varies

ANSWER:  A


4] What is the output of this C code?

    #include <stdio.h>

    int x = 0;

    void main()

    {

        int *const ptr = &x;

        printf("%p\n", ptr);

        ptr++;

        printf("%p\n ", ptr);

    }


a) 0 1

b) Compile time error

c) 0xbfd605e8 0xbfd605ec

d) 0xbfd605e8 0xbfd605e8

ANSWER:  B


5] What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int x = 0;

        int *ptr = &x;

        printf("%p\n", ptr);

        ptr++;

        printf("%p\n ", ptr);

    }

a) 0xbfd605e8 0xbfd605ec


b) 0xbfd605e8 0cbfd60520

c) 0xbfd605e8 0xbfd605e9

d) Run time error

ANSWER:  A


6]  What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int x = 0;

        int *ptr = &5;

        printf("%p\n", ptr);

    }


a) 5

b) Address of 5

c) Nothing

d) Compile time error

ANSWER:  D


7]  What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int k = 5;

        int *p = &k;

        int **m  = &p;

        **m = 6;

        printf("%d\n", k);

    }


a) 5

b) Compile time error

c) 6

d) Junk

ANSWER:  C


8]  What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        int *r = &p;

        printf("%d", (**r));

    }

a) 1

b) Compile time error

c) Address of a

d) Junk value

ANSWER:  B


9] What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        int **r = &p;

        printf("%p %p", *r, a);

    }

a) Different address is printed
b) 1 2
c) Same address is printed.
d) 1 1

ANSWER:  C


10] How many number of pointer (*) does C have against a pointer variable declaration?

a) 7

b) 127

c) 255

d) No limits.

ANSWER:  D


11] What is the output of this C code?

    #include <stdio.h>

    int main()

    {

        int a = 1, b = 2, c = 3;

        int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;

        int **sptr = &ptr1; //-Ref

        *sptr = ptr2;

    }

a) ptr1 points to a


b) ptr1 points to b

c) sptr points to ptr2

d) None of the mentioned

ANSWER:  B


12] What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        int **r = &p;

        printf("%p %p", *r, a);

    }

a) Different address is printed

b) 1 2

c) Same address is printed.

d) 1 1

ANSWER:  C


13] What substitution should be made to //-Ref such that ptr1 points to variable C?

    #include <stdio.h>

    int main()

    {

        int a = 1, b = 2, c = 3;

        int *ptr1 = &a;

        int **sptr = &ptr1;

        //-Ref

    }


a) *sptr = &c;

b) **sptr = &c;

c) *ptr1 = &c;

d) None of the mentioned.

ANSWER:  A


14] Which of the following declaration throw run-time error?

a) int **c = &c;

b) int **c = &*c;

c) int **c = **c;

d) None of the mentioned

ANSWER:  D


15] Comment on the output of this C code?

    #include <stdio.h>

    int main()

    {

        int a = 10;

        int **c -= &&a;

    }


a) You cannot apply any arithmetic operand to a pointer.

b) We don’t have address of an address operator

c) Both (a) and (b)

d) None of the mentioned.

ANSWER:  B


16] What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        int *r = &p;

        printf("%d", (**r));

    }


a) 1

b) Compile time error

c) Address of a

d) Junk value

ANSWER:  B


17] Comment on the output of this C code?

    #include <stdio.h>

    int main()

    {

        char *str = "This" //Line 1

        char *ptr = "Program\n"; //Line 2

        str = ptr; //Line 3

        printf("%s, %s\n", str, ptr); //Line 4

    }

a) Memory holding “this” is cleared at line 3

b) Memory holding “this” loses its reference at line 3

c) You cannot assign pointer like in Line 3

d) Output will be This, Program

ANSWER:  B


18] What type initialization is needed for the segment “ptr[3] = ’3′;” to work?

a) char *ptr = “Hello!”;

b) char ptr[] = “Hello!”;

c) Both (a) and (b)

d) None of the mentioned

ANSWER:  B


19] The syntax for constant pointer to address (i.e., fixed pointer address) is:

a) const <type> * <name>

b) <type> * const <name>

c) <type> const * <name>

d) Both (a) and (c)

ANSWER:  B


20] Comment on the output of this C code?

    #include <stdio.h>

    int add(int a, int b)

    {

        return a + b;

    }

    int main()

    {

        int (*fn_ptr)(int, int);

        fn_ptr = add;

        printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));

    }


a) Compile time error, declaration of a function inside main.

b) Compile time error, no definition of function fn_ptr.

c) Compile time error, illegal application of statement fn_ptr = add.

d) No Run time error, output is 5.

ANSWER:  D









Popular Posts