StructuresWhat is wrong with the following code?#include <stdio.h>struct Person { char *name; struct Person Mother, Father;}Anita;OptionsThe ; should appear after the } and Anita be defined later.The name should be defined as an arraystruct Person Mother, Father; must be defined as struct Person *Mother, *Father;There is no error in the code
Question
StructuresWhat is wrong with the following code?#include <stdio.h>struct Person { char *name; struct Person Mother, Father;}Anita;OptionsThe ; should appear after the } and Anita be defined later.The name should be defined as an arraystruct Person Mother, Father; must be defined as struct Person *Mother, *Father;There is no error in the code
Solution
The correct answer is: struct Person Mother, Father; must be defined as struct Person *Mother, *Father;
The reason is that in C, you cannot have fields in a structure that are of the same type as the structure itself. This would lead to an infinite size of the structure. However, you can have pointers to such structures. So, the Mother and Father fields should be defined as pointers to struct Person.
Similar Questions
why the above 2 lines of code is incorrect:
Which of the following cannot be structure member in c.Question 5Answera.Arrayb.Another structurec.None of thesed.Function
Nested structure program in c
StructuresWhat is wrong with the following code?#include <stdio.h>struct Person { char *name; struct Person Mother, Father;}Anita;OptionsThe ; should appear after the } and Anita be defined later.The name should be defined as an arraystruct Person Mother, Father; must be defined as struct Person *Mother, *Father;There is no error in the code
Which of the following cannot be a structure member?*1 pointA. FunctionB. ArrayC. StructureD. None of the above
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.