Pointer to structure — C++ MCQs

30
Score: 0
Attempted: 0/30
1. How do you declare a pointer to a structure Person?



2. How do you allocate memory dynamically for a structure pointer?



3. How do you access a member name of a structure via pointer p?



4. How do you free memory allocated for a structure pointer?



5. Which operator is used to access a member of a structure via pointer?
7. Can a pointer to a structure be passed to a function?



8. What is output?
struct Person { string name; int age; };
Person p1 = {"Ali",20};
Person *ptr = &p1;
cout << ptr->age;




9. Can a pointer to structure point to an array of structures?



10. How do you access 3rd element in an array of structures via pointer ptr?



11. Can you declare a pointer to a nested structure?



12. How do you declare a constant pointer to a structure?



13. How do you declare a pointer to a constant structure?



14. Can a pointer to structure be incremented to point to next element in an array?



15. Which of the following is correct syntax to access member of structure using pointer?



16. Can a structure pointer be initialized to nullptr?



17. What is output?
struct Person { string name; int age; };
Person *ptr = nullptr;
cout << (ptr == nullptr);




18. Can a pointer to structure be used to call a member function?
20. Can pointer to structure be part of another structure?



21. Can you pass a pointer to structure as function argument to modify original data?



22. How do you declare an array of pointers to structures?



23. How do you allocate memory for an array of pointers to structures?



24. How do you access member age of first pointer in array of structure pointers?



25. Can pointer to structure point to dynamically allocated nested structure?



26. How do you check if pointer to structure is valid before accessing members?



27. Can pointer to structure be used with sizeof operator?



28. Can pointer to structure be used in pointer arithmetic?



29. Can a pointer to structure be null-initialized at declaration?



30. Which of the following statements are true about pointer to structure?



Contents Copyrights Reserved By T4Tutorials