Fundamentals Of Data Structure MCQ'S SET-5

 



1] What is the output of this C code?

    #include <stdio.h>

    void f(char *k)

    {

        k++;

        k[2] = 'm';

    }

    void main()

    {

        char s[] = "hello";

        f(s);

        printf("%c\n", *s);

    }


a) h

b) e

c) m

d) o

ANSWER:  A


2] What is the output of this C code?

    #include <stdio.h>

    void main()

    {

        char s[] = "hello";

        s++;

        printf("%c\n", *s);

    }


a) Compile time error

b) h

c) e

d) o

ANSWER:  A


3] What is the output of this C code?

    #include <stdio.h>

    struct student

    {

        char *c;

    };

    void main()

    {

        struct student m;

        struct student *s = &m;

        s->c = "hello";

        printf("%s", s->c);

    }


a) hello

b) Run time error

c) Nothing

d) Depends on compiler

ANSWER:  A


4] What is the output of this C code?

    #include <stdio.h>

    struct student

    {

        char *c;

    };

    void main()

    {

        struct student *s;

        s->c = "hello";

        printf("%s", s->c);

    }

a) hello
b) Segmentation fault
c) Run time error
d) Nothing

ANSWER:  B


5] What is the output of this C code?

    #include <stdio.h>

    struct student

    {

        char *c;

    };

    void main()

    {

        struct student m;

        struct student *s = &m;

        s->c = "hello";

        printf("%s", m.c);

    }


a) Run time error

b) Nothing

c) hello

d) Varies

ANSWER:  C


6] What is the output of this C code?

    #include <stdio.h>

    struct student

    {

        char *c;

    };

    void main()

    {

        struct student m;

        struct student *s = &m;

        (*s).c = "hello";

        printf("%s", m.c);

    }


a) Run time error

b) Nothing

c) Varies

d) hello 

ANSWER:  D


7]  What is the output of this C code?

    #include <stdio.h>

    struct student

    {

        char *c;

    };

    void main()

    {

        struct student n;

        struct student *s = &n;

        (*s).c = "hello";

        printf("%p\n%p\n", s, &n);

    }


a) Different address

b) Run time error

c) Nothing

d) Same address

ANSWER:  D


8] What is the output of this C code?

    #include <stdio.h>

    struct p

    {

        int x[2];

    };

    struct q

    {

        int *x;

    };

    int main()

    {

        struct p p1 = {1, 2};

        struct q *ptr1;

        ptr1->x = (struct q*)&p1.x;

        printf("%d\n", ptr1->x[1]);

    }


a) Compile time error

b) Segmentation fault/code crash

c) 2

d) 1

ANSWER:  B


9] What is the output of this C code?

    #include <stdio.h>

    struct p

    {

        int x[2];

    };

    struct q

    {

        int *x;

    };

    int main()

    {

        struct p p1 = {1, 2};

        struct q *ptr1;

        ptr1->x = (struct q*)&p1.x;

        printf("%d\n", ptr1->x[1]);

    }


a) Compile time error

b) Segmentation fault/code crash

c) 2

d) 1

ANSWER:  B


10] What is the output of this C code?

    #include <stdio.h>

    struct p

    {

        int x;

        int y;

    };

    int main()

    {

        struct p p1[] = {1, 2, 3, 4, 5, 6};

        struct p *ptr1 = p1;

        printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);

    }


a) 1 5

b) 1 3

c) Compile time error

d) 1 4

ANSWER:  A


11] What is the output of this C code?

    #include <stdio.h>

    struct p

    {

        int x;

        char y;

    };

    int main(){

        struct p p1[] = {1, 92, 3, 94, 5, 96};

        struct p *ptr1 = p1;

        int x = (sizeof(p1) / sizeof(struct p));

        printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);

    }


a) Compile time error

b) Undefined behaviour

c) 1 3

d) 1 5 

ANSWER:  D


12] What is the output of this C code (considering sizeof char is 1 and pointer is 4)?

    #include <stdio.h>

    int main()

    {

        char *a[2] = {"hello", "hi"};

        printf("%d", sizeof(a));

        return 0;

    }


a) 9

b) 4

c) 8

d) 10

ANSWER:  A


13] What is the output of this C code?

    #include <stdio.h>

    int main()

    {

        char a[2][6] = {"hello", "hi"};

        printf("%d", sizeof(a));

        return 0;

    }


a) 9

b) 12

c) 8

d) 10

ANSWER:  B


14]  What is the output of this C code?

    #include <stdio.h>

    int main()

    {

        char a[2][6] = {"hello", "hi"};

        printf("%d", sizeof(a));

        return 0;

    }


a) 9

b) 12

c) 8

d) 10

ANSWER:  C


15]  Advantage of a multi-dimension array over pointer array.

a) Pre-defined size.

b) Input can be taken from user.

c) Faster Access.

d) All of the mentioned

ANSWER:  D


16]  Which of the following operation is possible using a pointer char?(Assuming declaration char *a;)

a) Input via %s

b) Generation of multidimensional array

c) Changing address to point at another location

d) All of the mentioned

ANSWER:  C


17]  Comment on the following two operations?

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

a) 1 will work, 2 will not

b) 1 and 2, both will work

c) 1 won’t work, 2 will work

d) Neither of them will work

ANSWER:  C


18] Comment on the following two operations?

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

a) 1 works, 2 doesn’t

b) 2 works, 1 doesn’t

c) Both of them work

d) Neither of them work

ANSWER:  D


19] Comment on the following two operations?

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

a) 1 works, 2 doesn’t

b) 2 works, 1 doesn’t

c) Both of them work

d) Neither of them work 

ANSWER:  B


20] Which of the following syntax is correct for command-line arguments?

a) int main(int var, char *varg[])

b) int main(char *argv[], int argc)

c) int main()
    {
        int argv, char *argc[];
    }

d) Both (a) and (b)

ANSWER:  A






Popular Posts