1. For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?
struct temp
{
int a : 13;
int b : 8;
int c : x;
}s;
struct temp
{
int a : 13;
int b : 8;
int c : x;
}s;
2. What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
strcpy(q.name, p.name);
ptrary[1] = &q;
printf("%s\n", ptrary[1]->name);
return 0;
}
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
strcpy(q.name, p.name);
ptrary[1] = &q;
printf("%s\n", ptrary[1]->name);
return 0;
}
3. Which of the following cannot be a structure member?
4. Bit fields can only be declared as part of a structure.
5. Which of the following reduces the size of a structure?
6. What will be the output of the following 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);
}
#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);
}
7. Which of the following uses structure?
8. What is the order for the following C declarations?
short a : 17;
int long y : 33;
short a : 17;
int long y : 33;
9. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u.p = {2};
printf("%d\n", u.p.x);
}
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u.p = {2};
printf("%d\n", u.p.x);
}
10. Presence of loop in a linked list can be tested by . . . . . . . .
Read More Section(Structure and Union)
Each Section contains maximum 100 MCQs question on Structure and Union. To get more questions visit other sections.