Knowee
Questions
Features
Study Tools

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

🧐 Not the exact question you are looking for?Go ask a question

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.

This problem has been solved

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

1/2

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.