3- ( Structure s) Choose the best answer on the following questions: (I). Which
ID: 3825971 • Letter: 3
Question
3- ( Structure s) Choose the best answer on the following questions:
(I). Which of the following accesses a variable in structure b?
A. b->var;
B. b.var;
C. *b-var;
D. b>-var;
(II). Which of the following accesses a variable in a pointer to a structure, *b?
A. b->var;
B. b.var;
C. *b-var;
D. *b>var;
(III). Which of the following is a properly defined struct?
A. struct {int a,b;}
B. struct a_struct {int a,b; }
C. struct a_struct int a,b;
D. struct a_struct {int a;};
(IV). Which properly declares a variable of struct foo?
A. struct foo;
B. struct foo var;
C. foo;
D. int foo;
(V.1) What is the output of this C code?
1. #include
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. no = 8;
11. printf("%d", no);
12. }
a) Nothing
b) Compile time error
c) Junk
d) 8
(V.2) How do you update the code above to correct the output.
Explanation / Answer
3) (I). Which of the following accesses a variable in structure b?
Answer:Option B. b.var;
(II). Which of the following accesses a variable in a pointer to a structure, *b?
Answer: Option A. b->var;
Explanation:Because in a structure pointer, the data element is declared as above only.
(III). Which of the following is a properly defined struct?
Answer:Option D. struct a_struct {int a;};
Explantion:The a_struct is declared as structure name and its data element is a.
(IV).Which properly declares a variable of struct foo?
Answer: Option B. struct foo var;
(V.1) What is the output of this C code?
1. #include
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. no = 8;
11. printf("%d", no);
12. }
Answer: Option b) Compile time error
(V.2) How do you update the code above to correct the output.
#include <stdio.h>
int main(void) {
struct student
{
char name[20];
};
struct student s;
int no = 8; // Here we are declaring the no as integer variable
printf("%d", no);
return 0;
}
Output:
8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.