Defining and using structures — C++ MCQs

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



2. How do you define a structure named Person with members name and age?



3. How do you declare a variable p1 of structure Person?



4. How do you access age of structure p1?



5. How do you initialize structure Person p1 with name “Ali” and age 25?



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



7. How do you access name through pointer ptr?



8. Can a structure contain another structure as a member?



9. Which of the following is correct syntax to declare an array of 5 Person structures?



10. What is the default access specifier for structure members in C++?



11. Can structure members be functions?



12. Which keyword is used to define a structure type?



13. Which of the following is correct to copy structure p1 to p2?



14. How do you pass a structure to a function?



15. How do you return a structure from a function?



16. Can structures have constructors in C++?



17. Can structure members be private in C++?



18. What is the size of an empty structure in C++?



19. Can a structure contain an array?



20. Which of the following allows structure members to be accessed outside the structure?



21. Which of the following is correct to declare a structure inside another structure?



22. What is output?
struct Test { int x; };
int main(){ Test t1={5}; cout << t1.x; }




23. How do you dynamically allocate a structure?



24. How do you free dynamically allocated structure memory?



25. Can structure have static members?



26. Which operator is used to access structure member through pointer?
28. Can structures have constant members?



29. Can a structure member be a pointer to the same structure type?



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



Contents Copyrights Reserved By T4Tutorials