This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Arrays of Structures – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
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\n", p[1].x);
}
a) Compile time error
b) 3
c) 2
d) 1
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
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\n", p->x);
}
a) 1
b) 2
c) 3
d) Compile time error
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
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 %d\n", p->x, ++p->x);
}
a) 1 2
b) 2 2
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
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 %d\n", p->x, p[2].y);
}
a) 1 0
b) Compile time error
c) 1 somegarbagevalue
d) Undefined behaviour
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
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[3].y);
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) None of the mentioned
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
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);
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) Undefined behaviour
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
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);
}
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) undefined behaviour
View Answer
Explanation: None.
8. What will be the output of the following C code on a 64-bit system?
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
a) 2
b) 4
c) 16
d) 8
View Answer
Explanation: On a 64-bit system, size of pointer is 8 bytes. Here, we are printing the size of an array of 2 structures, hence, the size will be 2×8 = 16 bytes.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Apply for C Internship
- Practice Computer Science MCQs
- Practice BCA MCQs
- Apply for Computer Science Internship