Plus Two Computer Science - Chapter 1: Structures and Pointers
Maximum Marks: 60 | Time: 2.5 Hours
Part A - Very Short Answer (1 mark each)
1. Define a structure.
Answer: A structure is a user-defined data type that groups different types of variables under one
name.
2. What is the use of the dot operator in C++?
Answer: It is used to access members of a structure variable.
3. Write the syntax to declare a pointer.
Answer: data_type *pointer_name;
4. What is a nested structure?
Answer: A structure that contains another structure as its member.
5. Define pointer.
Answer: A pointer is a variable that stores the address of another variable.
6. What is dynamic memory allocation?
Answer: Memory allocated during runtime using the 'new' operator.
7. Name the operator used to free dynamic memory.
Answer: delete
8. Write the syntax of declaring a self-referential structure.
Answer: struct node { int data; node *next; };
Part B - Short Answer (2 marks each)
9. Write a structure `stud` with `roll` and `name[20]`.
Answer: struct stud { int roll; char name[20]; };
10. Distinguish between arrays and structures.
Answer: Arrays store same data types; structures can store different data types.
11. What is a memory leak?
Answer: Memory not freed after allocation, causing memory waste.
12. Explain two arithmetic operations on pointers.
Answer: Addition (++, +) and subtraction (--, -) change the address stored in a pointer.
13. How do you dynamically create an integer using `new` keyword in C++?
Answer: int *p = new int;
14. Explain accessing structure elements using pointers.
Answer: Use '->' operator: ptr->element;
Part C - Short Essay (3 marks each)
15. Write the syntax and example for declaring structure and variable.
Answer: struct student { int id; char name[20]; } s1;
16. Explain dynamic array with syntax.
Answer: int *arr = new int[size]; // allocates array at runtime.
17. Use pointer to structure for employee data.
Answer: employee *eptr; eptr->ecode = 657346; cin >> eptr->salary;
18. Static vs Dynamic memory allocation.
Answer: Static: before runtime; Dynamic: during runtime using new/delete.
19. Relational operations on pointers.
Answer: == (equal), != (not equal) - compare memory addresses.
Part D - Essay (5 marks each)
20. Program to input 5 student data & display in reverse order using pointer.
Answer: struct student { int roll; char name[20]; } s[5];
for(int i=0;i<5;i++) cin>>s[i].roll>>s[i].name;
for(int i=4;i>=0;i--) cout<<s[i].roll<<s[i].name;
21. Structure `employee` pointer variable example.
Answer: struct employee { int ecode; char ename[15]; float salary; };
employee *eptr = new employee;
eptr->ecode = 101;
cin >> eptr->salary;
cout << eptr->ecode << eptr->salary;
22. Structure vs Array; Self-referential structure.
Answer: Array: same type; Structure: mixed types
Self-referential: struct node { int data; node *next; };