C Structure & Union Questions

Hello PrepSter,

If you find any errors in the quiz below kindly comment in the comment section and we will make it our priority to fix it.

Also if you have a better of the solution to the questions, please do comment them below and if we find it better than ours, we will post it in our website.

Question 1

Time: 00:00:00
What is the output of the output of the following program ?
#include<stdio.h>
struct ch
{
char a;
char b;
};

int main()
{
printf("%d", sizeof(struct ch));
return 0;
}

8

8

2

2

1

1

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
What is the expected output of the code below ?
#include<stdio.h>
struct ch
{
char a;
static int b;
};

int main()
{
printf("%d", sizeof(struct ch));
return 0;
}

8

8

6

6

4

4

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
Select the correct option related to the declaration of arr given below.
struct new 
{
int a;
float b;
};
struct new *arr[10];

An array with each element of type new.

An array with each element of type new.

A structure with 2 elements an int and a float being a pointer to an array of 10 elements.

A structure with 2 elements an int and a float being a pointer to an array of 10 elements.

A structure with 3 elements an int a float and an integer

A structure with 3 elements an int a float and an integer

An array with each element being a pointer to struct of new type.

An array with each element being a pointer to struct of new type.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Can there be a structure that has a element that has it's own type like this structure below ?
struct s
{
int a;
struct st i;
};

Yes.

Yes.

No.

No.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
Select the correct option for the following C program.
#include<stdio.h> 
struct new1
{
int a;
int b;
};
struct new2
{
int a;
int b;
};
int main()
{
struct new1 temp;
temp.a = 10;
temp.b = 10;
struct new2 temp1;
temp1.a = 11;
temp1.b = 10;
if(temp.a==temp1.a)
printf("Equal");
else
printf("Not equal");
return 0;
}

Equal

Equal

Not Equal

Not Equal

Compile error.

Compile error.

(null)

(null)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
What will be the output of the following code ?
#include<stdio.h> 
union test
{
int a;
char arr[8];
int b;
};

int main()
{
printf("%d", sizeof(union test));
return 0;
}

8

8

16

16

12

12

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
What is the output for the code given below ?
#include <stdio.h>
#include <string.h>
struct s
{
char elem[20];
};

int main()
{
struct s st1, st2;
strcpy(st1.elem, "PrepInsta");
st2 = st1;
st1.elem[0] = 'p';
printf("%s",st2.elem);
return 0;
}

PrepInsta

PrepInsta

prepInsta

prepInsta

Segmentation core dump.

Segmentation core dump.

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
What is the expected output of the following code ?
#include<stdio.h>
struct s
{
int a, b, c;
};

int main()
{
struct s new = {.b = 12, .c = 9, .a = 10};
printf("%d %d %d", new.a, new.b, new.c);
return 0;
}

9 10 12

9 10 12

12 9 10

12 9 10

10 12 9

10 12 9

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
Given that size of short is 2, float is 4 and long is 8 bytes. What will be the size of structure of x type.
struct { 
short a[5];
union {
float b;
long c;
}y;
}x;

10 bytes

10 bytes

64 bytes

64 bytes

14 bytes

14 bytes

18 bytes

18 bytes

120 bytes

120 bytes

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
What will be the output of the following program ?
#include‹stdio.h›
int main()
{
struct s
{
char site[] = "PrepInsta";
int x = 1299;
};
struct s *p;
printf("%d ", p->x);
printf("%s", p->site);
return 0;
}

1299 PrepInsta

1299 PrepInsta

1299

1299

(null)

(null)

Compilation error.

Compilation error.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]