Structure MCQ (Giridhar)
Structure MCQ (Giridhar)
Exercise No. :
Bitfields Date :
1
PROBLEM SOLVING
{
printf("%d\n", p[1].x);
}
a. Compile time error
b. 3
c. 2
d. 1
2
PROBLEM SOLVING
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
3
PROBLEM SOLVING
struct point
{
int x; int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, (p + 2)->y);
}
4
PROBLEM SOLVING
q.name = (char*)malloc(sizeof(char)*3);
strcpy(q.name, p.name);
q.next = &q; ptrary[1] = &q;
printf("%s\n", ptrary[1]->next->next->name);
}
a. 1
b. 2
c. 0
d. Depends on the compiler
5
PROBLEM SOLVING
int a : 2;
int b : 2;
};
int main() {
struct example e = {3, 2};
printf("%d %d\n", e.a, e.b);
return 0;
}
a)3 2
b)-1 -2
c)1 0
d)0 1
What will be the output of the following code?
union data {
int i;
float f;
char str[20];
};
int main() {
union data d;
d.i = 10;
10 printf("%d\n", d.i); Basic
d.f = 220.5;
printf("%d\n", d.i);
return 0;
}
a) 10 and 0
b) 10 and 220
c) 10 and some undefined value
d) Compilation error
.
6
PROBLEM SOLVING
union mix {
int a;
double b;
char c[9];
};
a)9 bytes
b)12 bytes
c)16 bytes
d)18 bytes
b)5 bytes
c)8 bytes
d)16 bytes