This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Arrays of Structures – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. The correct syntax to access the member of the ith structure in the array of structures is?
Assuming: struct temp { int b; }s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
View Answer
Explanation: None.
2. Comment on the output of the following C code.
#include <stdio.h>
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
a) No Compile time error, generates an array of structure of size 3
b) No Compile time error, generates an array of structure of size 9
c) Compile time error, illegal declaration of a multidimensional array
d) Compile time error, illegal assignment to members of structure
View Answer
Explanation: None.
3. Which of the following uses structure?
a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned
View Answer
Explanation: None.
4. What is the correct syntax to declare a function foo() which receives an array of structure in function?
a) void foo(struct *var);
b) void foo(struct *var[]);
c) void foo(struct var);
d) none of the mentioned
View Answer
Explanation: None.
5. What will be the output of the following C code? (Assuming size of int be 4)
#include <stdio.h>
struct temp
{
int a;
int b;
int c;
} p[] = {0};
main()
{
printf("%d", sizeof(p));
}
a) 4
b) 12
c) 16
d) Can’t be estimated due to ambiguous initialization of array
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student s[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
printf("%s%s", s[0].name, s[1].name);
s[1].name = "turing";
printf("%s%s", s[0].name, s[1].name);
}
a) alan alan alan turing
b) alan alan turing turing
c) alan turing alan turing
d) run time error
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
r = s;
printf("%s%s", r[0].name, r[1].name);
}
a) alan alan
b) Compile time error
c) Varies
d) Nothing
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s[2], r[2];
s[1] = s[0] = "alan";
printf("%s%s", s[0].name, s[1].name);
}
a) alan alan
b) Nothing
c) Compile time error
d) Varies
View Answer
Explanation: None.
9. What will be the output of the following C code?
#include <stdio.h>
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
a) 2
b) 4
c) 8
d) 0
View Answer
Explanation: None.
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.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice BCA MCQs
- Buy Computer Science Books
- Apply for Computer Science Internship
- Apply for C Internship
- Practice Computer Science MCQs