basicc++mcqRandom

C MCQ Questions and Answers on Structures and Pointers 2 | c programming questions answers

softwaretechit.com

Study C MCQ Questions and Answers on Structures and Pointers. C Structures are widely used in the code of hardware drivers and operating systems. Easily attend technical job interviews after reading these Multiple Choice Questions.

Go through C Theory Notes on Structures and Pointers before studying these questions.




1) What is the output of c program with structures.?

int main()

{

    struct car

    {int color;};

    struct garage

    {

        struct car mycar[10];

    }gar;

    struct car c1={5};

    gar.mycar[0]=c1;

    printf(“%d”,gar.mycar[0]);

    return 0;

}

A) NULL

B) 0

C) 5

D) Compiler error

Answer [=]

C

Explanation:

It is an example of nested structures.

2) What is the size of the below C structure in TurboC?

int main()

{

    struct books{

        int pages;

        char str[4];

    }b;

    printf(“%d”,sizeof(b));

    return 0;

}

A) 5

B) 6

C) 7

D) 8

Answer [=]

B

Explanation:

2+4= 6 bytes.

3) What is the output of C program with Structure pointer in TurboC.?

int main()

{

    struct books{

        int pages;

        char str[4];

    }*ptr;

    printf(“%d”,sizeof(ptr));

    return 0;

}

A) 2

B) 6

C) 7

D) 8

Answer [=]

B

Explanation:

Memory reserved will be the size of sum of individual elements.

4) In a nested structure definition, with country.state.district statement, memeber state is actually present in the structure.? (COUNTY, STATE, DISTRICT structures)

A) district

B) state

C) country

D) None of the above

Answer [=]

C

5) What is actually passed if you pass a structure variable to a function.?

A) Copy of structure variable

B) Reference of structure variable

C) Starting address of structure variable

D) Ending address of structure variable

Answer [=]

A

Explanation:

Yes. If you pass a structure variable by value without & operator, only a copy of the variable is passed. So changes made within that function do not reflect in the original variable.

6) What is the output of C program with structures.?

void show(int,int);

int main()

{

    struct paint{

        int type;

        int color;

    }p;

    p.type=1;

    p.color=5;

    show(p.type,p.color);

    return 0;

}

void show(int a,int b)

{

    printf(“%d %d”,a,b);

}

A) 1 1

B) 1 5

C) 5 1

D) Compiler error

Answer [=]

B

7) What is the output of C program with structures.?

int main()

{

    struct paint{

        int type;

        int color;

    }p1, p2;

    p1.type=1;

    p1.color=5;

    if(sizeof(p1)==sizeof(p2))

    {

        printf(“SAME”);

    }

    else

    {

        printf(“DIFFERENT”);

    }

    return 0;

}

A) SAME

B) DIFFERENT

C) Compiler error

D) None of the above

Answer [=]

A

Explanation:

Yes. Before and after initialization, size of a structure variable does not change.



8) Choose a correct statement about C structures.

A) A structure enables display of folder structure in OS.

B) A structure enables erasing contents in a folder in OS.

C) A structure enables to detect and respond to mouse clicks.

D) All the above

Answer [=]

D

9) Choose a correct statement about structure and array.?

A) An array stores only elements of same type. Accessing elements is easy.

B) A structure is preferred when different type elements are to be combined as a single entity.

C) An array implementation has performance improvements to structure

D) All the above

Answer [=]

D

10) What are the types of data allowed inside a structure.?

A) int, float, double, long double

B) char, enum, union

C) pointers and Same structure type members

D) All the above

Answer [=]

D

 

Leave a ReplyCancel reply

Exit mobile version