Here is a listing of C Objective Questions on “Arrays of Structures” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
struct point
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point*);
-
int main()
-
{
-
struct point p1[] = {1, 2, 3, 4};
-
foo(p1);
-
}
-
void foo(struct point p[])
-
{
-
printf("%dn", p[1].x);
-
}
a) Compile time error
b) 3
c) 2
d) 1
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
struct point
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point*);
-
int main()
-
{
-
struct point p1[] = {1, 2, 3, 4};
-
foo(p1);
-
}
-
void foo(struct point p[])
-
{
-
printf("%dn", p->x);
-
}
a) 1
b) 2
c) 3
d) Compile time error
Answer: a
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
struct point
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point*);
-
int main()
-
{
-
struct point p1[] = {1, 2, 3, 4};
-
foo(p1);
-
}
-
void foo(struct point p[])
-
{
-
printf("%d %dn", p->x, ++p->x);
-
}
a) 1 2
b) 2 2
c) Compile time error
d) Undefined behaviour
Answer: b
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
struct point
-
{
-
int x;
-
int y;
-
} p[] = {1, 2, 3, 4, 5};
-
void foo(struct point*);
-
int main()
-
{
-
foo(p);
-
}
-
void foo(struct point p[])
-
{
-
printf("%d %dn", p->x, p[2].y);
-
}
a) 1 0
b) Compile time error
c) 1 somegarbagevalue
d) Undefined behaviour
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
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 %dn", p->x, p[3].y);
-
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) None of the mentioned
Answer: c
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
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 %dn", p->x, (p + 2).y);
-
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) Undefined behaviour
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
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 %dn", p->x, (p + 2)->y);
-
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) undefined behaviour
Answer: b
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
struct student
-
{
-
char *c;
-
};
-
void main()
-
{
-
struct student s[2];
-
printf("%d", sizeof(s));
-
}
a) 2
b) 4
c) 16
d) 8
Answer: d
Clarification: None.