Nested structures — C++ MCQs

30
Score: 0
Attempted: 0/30
1. What is a nested structure in C++?



2. How do you define a nested structure?



3. How do you access the city member of Address in Person p?



4. Which of the following is correct declaration of nested structures?



5. Can a nested structure contain another structure?



6. How do you declare a pointer to a nested structure?



7. How do you access a nested member via pointer?



8. Can nested structures have functions?



9. Can you initialize a nested structure using curly braces?



10. How do you dynamically allocate memory for a nested structure Person?



11. How do you free memory allocated for nested structure pointer?



12. Can a nested structure be defined inside a class?



13. Can a nested structure be forward declared?



14. What is output?
struct Address { string city; };
struct Person { string name; Address addr; };
int main() { Person p = {"Ali", {"Karachi"}}; cout << p.addr.city; }




15. Can nested structures contain arrays?



16. Can you pass a nested structure to a function?



17. Can nested structures have constructors and destructors?



18. Can you assign one nested structure variable to another?



19. What is the default access specifier in nested structures?



20. Can nested structures contain pointers to themselves?



21. Which of the following is correct to define a nested structure pointer?



22. Can nested structures be private members of a class?



23. Can nested structures be used in arrays?



24. How do you access nested structure in an array of structures?



25. Can nested structures be passed to a function as a pointer?



26. Can nested structures have static members?



27. Which of the following allows you to define nested structure inside another structure and access members?



28. What is output?
struct Address { string city; };
struct Person { string name; Address addr; };
int main() { Person p = {"Ali", {"Lahore"}}; cout << p.name; }




29. Can nested structures be assigned using = operator?



30. Which of the following is true about nested structures in C++?



Contents Copyrights Reserved By T4Tutorials