Pointer to structure — C++ MCQs 30 Score: 0 Attempted: 0/30 1. How do you declare a pointer to a structure Person? (A) Person p; (B) struct Person p; (C) Person p; (D) struct Person *p; 2. How do you allocate memory dynamically for a structure pointer? (A) Person *p = new Person; (B) Person *p = malloc(sizeof(Person)); (C) Person *p; p = new Person; (D) All of the above 3. How do you access a member name of a structure via pointer p? (A) p.name (B) p->name (C) (*p).name (D) Both B and C 4. How do you free memory allocated for a structure pointer? (A) free(p); (B) delete p; (C) delete[] p; (D) release(p); 5. Which operator is used to access a member of a structure via pointer? 6. How do you assign address of a structure variable person1 to a pointer? (A) Person *p = person1; (B) Person *p = &person1; (C) Person *p = new Person(person1); (D) Person *p = *person1; 7. Can a pointer to a structure be passed to a function? (A) Yes, by value (B) Yes, by reference (C) Yes, by pointer (D) All of the above 8. What is output?struct Person { string name; int age; };Person p1 = {"Ali",20};Person *ptr = &p1;cout << ptr->age; (A) Ali (B) 20 (C) Garbage (D) Compile error 9. Can a pointer to structure point to an array of structures? (A) Yes (B) No (C) Only 1D arrays (D) Only 2D arrays 10. How do you access 3rd element in an array of structures via pointer ptr? (A) ptr[2].member (B) (ptr+2)->member (C) Both A and B (D) ptr->member[2] 11. Can you declare a pointer to a nested structure? (A) Yes (B) No (C) Only static members (D) Only if global 12. How do you declare a constant pointer to a structure? (A) Person * const p; (B) const Person *p; (C) const Person * const p; (D) All of the above 13. How do you declare a pointer to a constant structure? (A) Person * const p; (B) const Person *p; (C) const Person * const p; (D) Person *p const; 14. Can a pointer to structure be incremented to point to next element in an array? (A) Yes (B) No (C) Only if dynamic array (D) Only if 2D array 15. Which of the following is correct syntax to access member of structure using pointer? (A) (*ptr).member (B) ptr->member (C) Both A and B (D) ptr.member 16. Can a structure pointer be initialized to nullptr? (A) Yes (B) No (C) Only static (D) Only global 17. What is output?struct Person { string name; int age; };Person *ptr = nullptr;cout << (ptr == nullptr); (A) 1 (B) 0 (C) Garbage (D) Compile error 18. Can a pointer to structure be used to call a member function? 19. Can you assign one structure pointer to another? (A) Yes (B) No (C) Only if same type (D) Only dynamic memory 20. Can pointer to structure be part of another structure? (A) Yes (B) No (C) Only static (D) Only dynamic 21. Can you pass a pointer to structure as function argument to modify original data? (A) Yes (B) No (C) Only arrays (D) Only nested structures 22. How do you declare an array of pointers to structures? (A) Person *arr[5]; (B) struct Person arr[5]; (C) Both A and B (D) Person arr[5]; 23. How do you allocate memory for an array of pointers to structures? (A) arr[i] = new Person; (B) arr = new Person[5]; (C) arr[i] = malloc(sizeof(Person)); (D) Both A and C 24. How do you access member age of first pointer in array of structure pointers? (A) arr[0].age (B) arr[0]->age (C) (*arr[0]).age (D) Both B and C 25. Can pointer to structure point to dynamically allocated nested structure? (A) Yes (B) No (C) Only arrays (D) Only global 26. How do you check if pointer to structure is valid before accessing members? (A) if(ptr != nullptr) (B) if(ptr == NULL) (C) if(ptr > 0) (D) Both A and B 27. Can pointer to structure be used with sizeof operator? (A) Yes, sizeof(*ptr) gives size of structure (B) No (C) Only for dynamic memory (D) Only for arrays 28. Can pointer to structure be used in pointer arithmetic? (A) Yes (B) No (C) Only if array (D) Only if dynamic memory 29. Can a pointer to structure be null-initialized at declaration? (A) Yes, Person *ptr = nullptr; (B) No (C) Only global (D) Only static 30. Which of the following statements are true about pointer to structure? (A) Can access members via -> (B) Can point to dynamic structures (C) Can be part of arrays (D) All of the above Related Posts:String length Program Using Pointer to Structure in C++ Pointer declaration and initialization — C++ MCQsPointer arithmetic — C++ MCQswrite a c program to sort a 1d array using pointer by applying bubble sort techniqueC++ Array with pointerWhile declaring pointer variables which operator do we use?