Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures

Get the most accurate TN Board Solutions for Class 11 Computer Science Chapter 12 Arrays and Structures here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 11 Computer Science. Our expert-created answers for Class 11 Computer Science are available for free download in PDF format.

Detailed Chapter 12 Arrays and Structures TN Board Solutions for Class 11 Computer Science

For Class 11 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 11 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 12 Arrays and Structures solutions will improve your exam performance.

Class 11 Computer Science Chapter 12 Arrays and Structures TN Board Solutions PDF

Samacheer Kalvi 11th Computer Science Guide Chapter 12 Arrays And Structures

Book Evaluation

Part - I

Choose The Correct Answer

 

Question 1. Which of the following is the collection of variables of the same type that are referenced by a common name?
(a) int
(b) float
(c) Array
(d) class
Answer: (c) Array
In simple words: An array helps you store many values of the same type, like a list of numbers, all under one main name. It makes organizing similar data easy.

🎯 Exam Tip: Remember that arrays store data of the *same type* and are accessed using a *common name* with an index.

 

Question 2. Array subscripts always start with which number?
(a) -1
(b) 0
(c) 2
(d) 3
Answer: (b) 0
In simple words: In most programming, when you count items in a list like an array, you start counting from zero, not one. So, the first item is at position 0.

🎯 Exam Tip: Always remember that array indexing is zero-based in C++ and many other languages, meaning the first element is at index 0.

 

Question 3. int age[ ]={6,90,20,18,2}; How many elements are there in this array?
(a) 2
(b) 5
(c) 6
(d) 4
Answer: (b) 5
In simple words: Just count how many numbers are inside the curly brackets to know how many items are in the array. This array has five numbers.

🎯 Exam Tip: When an array is initialized with values, count the values to find the number of elements. The compiler automatically determines the size.

 

Question 4. cin>>n[3]; To which element does this statement accept the value?
(a) 2
(b) 3
(c) 4
(d) 5
Answer: (c) 4
In simple words: Because array counting starts from zero, the item at position [3] is actually the fourth item in the list. So, the input goes into the 4th element.

🎯 Exam Tip: If the index is 'x', the actual element position is 'x+1' due to zero-based indexing. Thus, `n[3]` refers to the 4th element.

 

Question 5. By default, the string end with which character?
(a) \0
(b) \t
(c) \n
(d) \b
Answer: (a) \0
In simple words: Strings are special lists of letters. To show where a string finishes, a hidden character called a null character (`\0`) is automatically put at its very end.

🎯 Exam Tip: A null terminator `\0` is crucial for C-style strings, allowing functions to know where the string ends. Without it, string operations can lead to errors.

Part - II

Very Short Answers

 

Question 1. What is Traversal in an Array?
Answer: Traversal in an array means visiting each element of the array at least one time to do some action. For example, showing all the elements stored in an array is a common way to traverse it. This process ensures that every piece of data in the array is looked at or used.
In simple words: Traversal is when you visit every single item in an array, one by one, to do something with each item.

🎯 Exam Tip: Emphasize that traversal involves accessing *each element at least once* and can be done for various operations, not just display.

 

Question 2. What is Strings?
Answer: A string is like a line of characters, where each character can be a letter, a number, or a symbol. Every string is automatically finished with a null character (`\0`). This special character tells the program where the string ends. For example, "hello" is stored as 'h', 'e', 'l', 'l', 'o', '\0'.
In simple words: A string is a group of letters, numbers, or symbols put together, and it always ends with a special `\0` character.

🎯 Exam Tip: Remember to mention both that strings are *sequences of characters* and that they are *null-terminated* in C++.

 

Question 3. What is the syntax to declare two - dimensional array?
Answer: The way to declare a two-dimensional (2-D) array is:
`datatype array_name[row-size][col-size];`
In this declaration:
`datatype` is any valid C++ data type (like `int`, `float`, `char`).
`array_name` is the name you give to your 2-D array.
`row-size` tells how many rows the array will have.
`col-size` tells how many columns the array will have. Think of it like a table with rows and columns.
In simple words: To make a 2-D array (like a grid), you write the type of data, then a name, then `[number of rows]` and `[number of columns]`.

🎯 Exam Tip: Clearly define each part of the syntax for declaring a 2-D array, especially `row-size` and `col-size` and their meaning.

Part - III

Short Answers

 

Question 1. Define an Array. What are the types?
Answer: An array is a collection of variables that are all of the same kind, and they are all referred to by a common name. This lets you store multiple related values together. For example, if you want to store 10 student ages, you can use one array instead of 10 separate variables.
There are different types of arrays commonly used in C++:

  • One-dimensional arrays
  • Two-dimensional arrays
  • Multi-dimensional arrays

In simple words: An array is a list of similar items that share one name. There are three main types: single-row, grid-like (two-dimensional), and even bigger (multi-dimensional).

🎯 Exam Tip: Provide a clear definition of an array and then list its common types. Understanding the basic definition is key before diving into types.

 

Question 2. Write with a note an Array of strings.
Answer: An array of strings is basically a two-dimensional list made of characters. The first index (number of rows) tells you how many strings you can store, and the second index (number of columns) tells you the longest possible length for each string. It's good practice to make the column size one character bigger to hold the null character (`\0`) at the end of each string. For example, the declaration `char name[7][10];` means you can store 7 strings, and each string can have a maximum length of 9 characters (plus one for the null character).
In this example:
No. of rows = 7;
No. of columns = 10;
This means we can store 7 strings, and each string can be up to 10 characters long, including the `\0` character.
In simple words: An array of strings is like a list where each item is a word or phrase. You decide how many words to store (rows) and how long each word can be (columns).

🎯 Exam Tip: Explain both indices: the first for *number of strings* and the second for *maximum length of each string*, and don't forget the null terminator's space requirement.

 

Question 3. Write a C++ program to accept and print your name?
Answer:
PROGRAM
`#include`
`using namespace std;`
`int main()`
`{`
`char str[100];`
`cout<< "Enter your name :";`
`cin.get(str,100);`
`cout<< "You name is : " << str <`return 0;`
`}`
This program first asks the user for their name. Then, it reads the name using `cin.get()` which can handle spaces. Finally, it prints the entered name back to the user. `cin.get()` is helpful because `cin` (without `.get()`) would stop reading at the first space.
In simple words: This program asks for your name and then shows it on the screen. It uses a special command to read your whole name, even if it has spaces.

🎯 Exam Tip: When writing C++ programs for strings with spaces, remember to use `cin.get()` or `getline()` instead of just `cin` to read the full line.

Part - IV

Explain In Detail

 

Question 1. Write a c++ program to find the difference between two matrix.
Answer:
PROGRAM
`#include`
`#include`
`using namespace std;`
`int main()`
`{`
`int row, col, m1[10][10], m2[10][10], sum[10][10];`
`cout<<"Enter the number of rows : ";`
`cin>>row;`
`cout<<"Enter the number of columns :";`
`cin>>col;`
`cout<< "Enter the elements of first matrix: "<`for (int i = 0;i`for (int j = 0;j`cin>>m1[i][j];`
`cout<< "Enter the elements of second matrix: "<`for (int i = 0;i`for (int j = 0;j`cin>>m2[i][j];`
`cout<<"Output: "<`for (int i = 0;i`{`
`for (int j = 0;j`{`
`sum[i][j]=m1[i][j] - m2[i][j]; cout<`}`
`cout<`}`
`getch();`
`return 0;`
`}`
This C++ program calculates the difference between two matrices. It first asks the user to enter the number of rows and columns, then the elements for both matrices. Finally, it subtracts the corresponding elements of the second matrix from the first and prints the resulting difference matrix. Matrices are widely used in computer graphics and scientific calculations.
In simple words: This program takes two number grids (matrices) from you. It subtracts each number in the second grid from the matching number in the first grid and then shows you the new grid with the answers.

🎯 Exam Tip: Ensure your loops iterate through both rows and columns correctly, and that matrix dimensions match for subtraction. The `conio.h` header is specific to older compilers like Turbo C++.

 

Question 2. How will you pass two dimensional array to a function explain with example.
Answer: You can pass a two-dimensional array to a function in C++ by specifying the number of columns, while the number of rows can be optional. This allows the function to know the layout of the array. Here is an example of a C++ program that displays values from a two-dimensional array by passing it to a function:
PROGRAM
`#include`
`using namespace std;`
`void display (int n[3][2]);`
`int main()`
`{`
`int num[3][2] = { {3, 4}, {9, 5}, {7, 1} };`
`display(num);`
`return 0;`
`}`
`void display(int n[3][2])`
`{`
`cout << "\n Displaying Values" << endl;`
`for (int i=0; i<3; i++)`
`{`
`for (int j=0; j<2; j++)`
`{`
`cout << n[i][j] << " ";`
`}`
`cout << endl << endl;`
`}`
`}`
Output
Displaying Values
3 4
9 5
7 1
In this program, the `display` function takes a 2-D array `n[3][2]` as input. The main function `int main()` creates a 2-D array `num` and then calls `display(num)` to print its elements. When passing a 2-D array, the column size must always be included in the function parameter so the compiler can correctly calculate memory addresses.
In simple words: To send a 2-D array (like a grid) to a function, you write its name and then its size, specifically how many columns it has. The example shows how to pass a grid of numbers to a function that then prints them out.

🎯 Exam Tip: When passing a multi-dimensional array to a function in C++, the dimensions for all but the first array must be specified in the function parameter for correct memory access.

11th Computer Science Guide Arrays And Structures Additional Questions And Answers

Choose The Correct Answer (1 Mark)

 

Question 1. The size of the array is referred to as its ………………..
(a) dimension
(b) direction
(c) location
(d) space
Answer: (a) dimension
In simple words: The "dimension" of an array tells you its size or how many items it can hold. It defines the array's extent.

🎯 Exam Tip: The term 'dimension' refers to the number of indices an array has, which also determines its overall size and structure.

 

Question 2. …………… is an easy way of storing multiple values of the same type referenced by a common name.
(a) Variables
(b) Literals
(c) Array
(d) None of the options
Answer: (c) Array
In simple words: An array is a simple way to keep a list of many similar values, all under one shared name. It groups related data.

🎯 Exam Tip: An array's key features are storing *multiple values*, being of the *same type*, and having a *common name*.

 

Question 3. Displaying all the elements in an array is an example of ………………..
(a) memory allocation
(b) call by reference
(c) traversal
(d) None of the options
Answer: (c) traversal
In simple words: When you look at every item in an array, one by one, to show them all, that action is called traversal. It means going through the whole list.

🎯 Exam Tip: Traversal specifically means visiting each element. Other options refer to memory handling or function calls.

 

Question 4. A (n) ………………….. is a collection of variables of the same type that are referenced by a common name.
(a) Structures
(b) Array
(c) Unions
(d) None of the options
Answer: (b) Array
In simple words: An array is a group of variables that are all the same kind and can be called by one main name. It helps keep similar data together.

🎯 Exam Tip: Remember the core definition of an array: a collection of *same-type variables* referenced by a *single name*.

 

Question 5. During ……………….. the array of elements cannot be initialized more than its size.
(a) declaration
(b) initialization
(c) assigning
(d) execution
Answer: (b) initialization
In simple words: When you first give values to an array (initialization), you cannot put more items in it than its declared size. The array has a fixed capacity.

🎯 Exam Tip: Array size is fixed after declaration. Attempting to initialize with more elements than declared will result in a compilation error.

 

Question 6. The …………….. of the array is referred to as its dimension.
(a) Elements
(b) Size
(c) Format
(d) None of the options
Answer: (b) Size
In simple words: The "size" of an array tells you how many items it can hold, and this is also called its dimension. This determines the array's overall capacity.

🎯 Exam Tip: While 'dimension' relates to how an array is structured (e.g., 1D, 2D), 'size' directly indicates the total number of elements it contains.

 

Question 7. To pass an array to a function in C++, the function needs the array name as ………………..
(a) a function
(b) an argument
(c) global object
(d) string
Answer: (b) an argument
In simple words: When you want a function to use an array, you send the array's name as an "argument" to that function. This is how the function gets access to the array's data.

🎯 Exam Tip: Passing the array name as an argument effectively passes its base address, allowing the function to access and modify the array elements.

 

Question 8. …………………. is a type of arrays used in C++.
(a) One-dimensional array
(b) Two-dimensional array
(c) Multidimensional array
(d) All of the options
Answer: (d) All of the options
In simple words: C++ can use all types of arrays: simple lists (one-dimensional), grids (two-dimensional), and even more complex layouts (multi-dimensional).

🎯 Exam Tip: Be familiar with all three main types of arrays: one-dimensional (linear lists), two-dimensional (matrices), and multi-dimensional (arrays of arrays of arrays).

 

Question 9. A structure without a name tag is called ………………..
(a) homogenous structure
(b) anonymous structure
(c) array of structure
(d) dynamic memory
Answer: (b) anonymous structure
In simple words: If you create a "structure" but don't give it a specific name, it's called an anonymous structure. It's like having a nameless container for data.

🎯 Exam Tip: Anonymous structures are useful for defining a type once without needing to refer to it by name elsewhere, often used for specific data objects.

 

Question 10. A one-dimensional array represents values that are stored in a single …………….
(a) Row
(b) Column
(c) Either A or B
(d) None of the options
Answer: (c) Either A or B
In simple words: A simple list (one-dimensional array) stores its values either in a single line (row) or a single stack (column). It's a linear arrangement.

🎯 Exam Tip: A one-dimensional array is a linear data structure, meaning its elements are arranged sequentially and can be visualized as either a row or a column.

 

Question 11. Array size should be specified with …………………
(a) square brackets[ ]
(b) Parenthesis ( )
(c) Curly braces{ }
(d) Angle brackets < >
Answer: (a) square brackets[ ]
In simple words: When you tell the computer how big an array should be, you always put the size number inside square brackets. This is the standard way to define array dimensions.

🎯 Exam Tip: Square brackets `[]` are used exclusively for specifying array sizes and accessing elements by index. Incorrect brackets will lead to syntax errors.

 

Question 12. In an array declaration, ……………… defines how many elements the array will hold.
(a) array_name
(b) array_size
(c) data_type
(d) None of the options
Answer: (b) array_size
In simple words: When you make an array, the "array size" is what tells it exactly how many items it can store. This determines its capacity.

🎯 Exam Tip: The array size is critical; it directly dictates the memory allocated for the array and the number of elements it can store. Defining the size is an important step in declaring an array.

 

Question 13. In an array declaration, …………………. declares the basic type of the array, which is the type of each element in the array.
(a) array_name
(b) array_size
(c) data type
(d) None of the options
Answer: (c) data type
In simple words: When you create an array, the "data type" is what tells the computer what kind of items (like whole numbers, decimal numbers, or letters) will be stored in it. All items in the array must be of this same type.

🎯 Exam Tip: The data type specifies the kind of values the array will store (e.g., `int` for integers, `char` for characters) and ensures all elements are consistent.

 

Question 14. In an array declaration, ……………….. specifies the name with which the array will be referenced
(a) array_name
(b) array_size
(c) data type
(d) None of the options
Answer: (a) array_name
In simple words: The "array name" is the label you give to your array so you can easily find and use it later in your program. It's how you refer to the entire collection of data.

🎯 Exam Tip: The array name serves as a handle to the entire collection of elements and is used to access individual elements along with their indices.

 

Question 15. The array subscript always starts with ………………
(a) 0
(b) 1
(c) -1
(d) None of the options
Answer: (a) 0
In simple words: When you are counting the positions of items in an array, you always begin counting from zero. So, the very first item is at position 0.

🎯 Exam Tip: A fundamental concept in array manipulation is zero-based indexing; consistently remember that `array[0]` is the first element.

 

Question 16. The subscript always is a(n) ………………value.
(a) Integer
(b) Unsigned integer
(c) Signed integer
(d) float
Answer: (b) Unsigned integer
In simple words: The number you use to point to an item in an array (the subscript) must always be a whole number that is not negative. This ensures it's a valid position.

🎯 Exam Tip: Subscripts must be non-negative integers. While a plain `int` can work, an `unsigned int` is conceptually more accurate as indices cannot be negative.

 

Question 17. In Turbo C++, int data type requires …………….. bytes of memory.
(a) 4
(b) 8
(c) 2
(d) 1
Answer: (c) 2
In simple words: In the Turbo C++ compiler, an 'int' variable is given 2 bytes of space in the computer's memory. This means it can hold numbers within a certain range.

🎯 Exam Tip: Remember that the memory allocated for data types like `int` can vary between different compilers and operating systems. Always check the specific environment if precise memory usage is critical.

 

Question 18. In Dev C++, int data type requires ………………. bytes of memory,
(a) 4
(b) 8
(c) 2
(d) 1
Answer: (a) 4
In simple words: When you use the Dev C++ compiler, an 'int' variable uses 4 bytes of memory space. This allows it to store a larger range of whole numbers compared to a 2-byte 'int'.

🎯 Exam Tip: Be aware of compiler differences, as they affect the size of data types and thus the memory footprint of your programs.

 

Question 19. The memory space allocated for an array can be calculated using the -formula.
(a) Number of bytes allocated for the type of array + Number of elements
(b) Number of bytes allocated for the type of array x Number of elements
(c) Number of bytes allocated for the type of array – Number of elements
(d) None of the options
Answer: (b) Number of bytes allocated for the type of array x Number of elements
In simple words: To find out how much memory an array uses, you multiply the memory needed for one item by the total count of items in the array. This simple calculation helps to predict memory usage.

🎯 Exam Tip: The formula is essential for calculating memory usage efficiently. Always ensure you know the size of one element in bytes for the specific data type.

 

Question 20. An array can be initialized at the time of its ………………
(a) Declaration
(b) Process
(c) Either A or B
(d) None of the options
Answer: (a) Declaration
In simple words: You can give an array its first values right when you create it, which is called declaration. This makes the array ready to use immediately.

🎯 Exam Tip: Initializing an array during declaration makes your code cleaner and helps prevent unexpected "garbage" values. It's good practice to provide initial values when possible.

 

Question 21. Unless an array is initialized, all the array elements contain ……………..values.
(a) Null
(b) Default
(c) Garbage
(d) None of the options
Answer: (c) Garbage
In simple words: If you don't set initial values for an array, the memory locations will have old, random data left over from previous uses. This unknown data is called "garbage" values.

🎯 Exam Tip: Always initialize your arrays, especially if you intend to use their values immediately. Using uninitialized values can lead to unpredictable program behavior and bugs.

 

Question 22. While declaring and Initializing values In an array, the values should be given within the ……………..
(a) square brackets[ ]
(b) Parenthesis ( )
(c) Curly braces{ }
(d) Angle brackets < >
Answer: (c) Curly braces{ }
In simple words: When you set the starting values for an array, you must list them inside curly braces. For example, `int arr[] = {1, 2, 3};`.

🎯 Exam Tip: Correct syntax is crucial. Using curly braces for array initialization is standard in C++ and many other languages, making your code readable and functional.

 

Question 23. The …………….. of an array may be optional when the array is initialized during declaration.
(a) Data type
(b) Size
(c) Name
(d) None of the options
Answer: (b) Size
In simple words: If you give an array its first values when you create it, you don't always have to say how big it is. The computer can figure out the size by counting the values you provide.

🎯 Exam Tip: While optional with initialization, explicitly stating the size improves clarity and can prevent unintended array sizes, especially in larger projects.

 

Question 24. The subscript in the bracket can be a(n) ……………….
(a) Variable
(b) Constant
(c) Expression that evaluates to an integer
(d) Either A or B or C
Answer: (d) Either A or B or C
In simple words: The number used inside the square brackets to point to an array element can be a simple number, a changeable value, or even a math problem that gives a whole number. This makes array access flexible.

🎯 Exam Tip: Regardless of its form, the subscript must always resolve to a non-negative integer within the array's bounds to avoid errors.

 

Question 25. Accessing each element of an array at least once to perform any operation is known as ………………..
(a) Traversal
(b) Process
(c) Reference
(d) None of the options
Answer: (a) Traversal
In simple words: When you go through every single item in an array to do something with it, like printing it out or checking its value, this action is called traversal. It's like visiting every house on a street.

🎯 Exam Tip: Traversal is a fundamental operation for arrays, often implemented using loops (for, while) to iterate through all elements systematically.

 

Question 26. …………………. is a process of finding a particular value present in a given set of numbers.
(a) Filtering
(b) Searching
(c) Seeking
(d) None of the options
Answer: (b) Searching
In simple words: The act of looking for a specific item or number within a list or group of items is called searching. It helps you locate if a certain value exists and where it is.

🎯 Exam Tip: Searching algorithms are vital for data retrieval. Common types include linear search and binary search, each with different efficiency characteristics.

 

Question 27. The ………………. compares each element of the list with the value that has to be searched until all the elements in the array have been traversed and compared.
(a) Linear search
(b) Sequential search
(c) Either A or B
(d) None of the options
Answer: (c) Either A or B
In simple words: Linear search and sequential search are the same thing. They both mean checking each item in a list one by one until the item you are looking for is found, or until the end of the list is reached.

🎯 Exam Tip: Linear search is simple but can be slow for large arrays. For unsorted data, it's often the only option, but for sorted data, more efficient methods exist.

 

Question 28. A ……………. is defined as a sequence of characters where each character may be a letter, number, or a symbol.
(a) String
(b) Character
(c) Literal
(d) Identifier
Answer: (a) String
In simple words: A string is like a chain of letters, numbers, or symbols put together in a specific order. Each piece in the chain is a single character.

🎯 Exam Tip: In C++, strings are often implemented as character arrays, which means they are stored as a continuous block of memory for individual characters.

 

Question 29. In C++, there is no basic data type to represent a …………….
(a) String
(b) Character
(c) Literal
(d) float
Answer: (a) String
In simple words: Unlike some other programming languages, C++ doesn't have a simple, built-in data type just for strings. Instead, strings are usually handled using character arrays or special string classes.

🎯 Exam Tip: While C++ doesn't have a primitive `string` type, it provides `char` arrays for C-style strings and the powerful `std::string` class from the `` library for easier string manipulation.

 

Question 30. How much memory required for the following array? char country[6];
(a) 12 bytes
(b) 6 bytes
(c) 60 Bytes
(d) 24 bytes
Answer: (b) 6 bytes
In simple words: Since a `char` (character) usually takes 1 byte of memory, an array designed to hold 6 characters (`char country[6]`) will need a total of 6 bytes of memory. This allows it to store 6 individual characters.

🎯 Exam Tip: Remember that each character in C++ typically consumes 1 byte. The size of a character array is simply the number of elements multiplied by 1 byte.

 

Question 31. …………….. is a way of initializing the character array:
(a) char country[6]={T, β€˜N’ β€˜D’ β€˜I’, β€˜A’, β€˜\0’};
(b) char country[ ]=”INDIA”;
(c) char country[ ]={T, β€˜N’, β€˜D’, T, β€˜A’ β€˜\0’};
(d) Either A or B or C
Answer: (d) Either A or B or C
In simple words: You can initialize a character array (string) in several correct ways. You can list each character separately in curly braces, or you can use a string enclosed in double quotes. Both methods automatically include the null terminator (`\0`) when using a string literal.

🎯 Exam Tip: Option (b) is the most common and convenient way to initialize a C-style string. Always remember that C-style strings require a null terminator (`\0`) at the end.

 

Question 32. Which is a correct statement from the following?
(a) At the end of the string, a null character is automatically added by the compiler.
(b) If the size of the array is not explicitly mentioned, the compiler automatically calculates the size of the array based on the number of elements in the list and allocates space accordingly.
(c) In the initialization of the string, if all the characters are not initialized, then the rest of the characters will be filled with NULL.
(d) All the options
Answer: (d) All the options
In simple words: All these statements are true about arrays and strings in C++. The compiler helps by adding a null character to string literals, figuring out array sizes when not given, and filling unused space with nulls during string initialization.

🎯 Exam Tip: Understanding these compiler behaviors is key to avoiding common string and array-related bugs and writing more robust C++ code.

 

Question 33. In C++,………………. is used to read a line of text including blank spaces.
(a) cin.get( )
(b) cin
(c) put( )
(d) None of the options
Answer: (a) cin.get( )
In simple words: In C++, the `cin.get()` function is used to read a whole line of text, even if it has spaces in it. The regular `cin` stops reading when it finds a space.

🎯 Exam Tip: Be aware that `cin` stops reading at whitespace, making `cin.get()` or `getline()` necessary when reading input that might contain spaces, like full names or sentences.

 

Question 34. ………………. function can read the characters till it encounters a newline character or a delimiter specified by the user.
(a) getline( )
(b) put
(c) puts( )
(d) None of the options
Answer: (a) getline( )
In simple words: The `getline()` function is useful because it can read characters from the input stream until it sees a new line or a special stop character that you tell it to look for. This allows it to read entire phrases or sentences.

🎯 Exam Tip: The `getline()` function (especially `std::getline` with `std::string`) is highly recommended for reading lines of text in C++ due to its robustness and flexibility.

 

Question 35. …………………. arrays are a collection of similar elements where the elements are stored in a certain number of rows and columns.
(a) One dimensional
(b) Two dimensional
(c) Multidimensional
(d) All the options
Answer: (b) Two dimensional
In simple words: Arrays that hold items in a grid-like shape, with both rows and columns, are called two-dimensional arrays. They are useful for organizing data like a table.

🎯 Exam Tip: Two-dimensional arrays are often visualized as matrices or tables and are commonly used for tasks like image processing, game boards, or storing tabular data.

 

Question 36. In two dimensional arrays, …………………. size is compulsory.
(a) Column
(b) Row
(c) Both A and B
(d) None of the options
Answer: (a) Column
In simple words: For a two-dimensional array, you always have to tell the computer the size of its columns. This is important because the computer needs to know how to move from one row to the next in memory.

🎯 Exam Tip: The column size is crucial for the compiler to correctly calculate memory addresses for elements in subsequent rows, even if the row size is omitted during initialization.

 

Question 37. In two dimensional arrays, …………….. size is optional.
(a) Column
(b) Row
(c) Both A and B
(d) None of the options
Answer: (b) Row
In simple words: When you create a two-dimensional array and immediately give it all its starting values, you don't always have to specify the number of rows. The computer can figure it out by counting the rows of values you provide.

🎯 Exam Tip: The row size can be optional only if the array is fully initialized at the time of declaration, allowing the compiler to deduce its dimensions from the provided values.

 

Question 38. int A[3][4]; How many elements are there in the array β€œA”?
(a) 3
(b) 4
(c) 7
(d) 12
Answer: (d) 12
In simple words: To find the total number of items in a two-dimensional array, you multiply the number of rows by the number of columns. In this case, 3 rows times 4 columns equals 12 elements.

🎯 Exam Tip: For a multi-dimensional array, the total number of elements is always the product of all its dimensions (e.g., rows * columns for a 2D array).

 

Question 39. The two-dimensional array uses ………………. index values to access a particular element in it.
(a) two
(b) one
(c) three
(d) many
Answer: (a) two
In simple words: To find a specific item in a two-dimensional array, you need two index numbers: one for its row and one for its column. This helps pinpoint the exact location.

🎯 Exam Tip: Always specify both a row index and a column index when accessing an element in a 2D array, like `array[row_index][column_index]`.

 

Question 40. In a two dimensional array, the first index specifies the …………….. value.
(a) Column
(b) Row
(c) Both A and B
(d) None of the options
Answer: (b) Row
In simple words: When you write `array[X][Y]`, the first number, `X`, always tells you which row the item is in. This is the standard way to reference elements.

🎯 Exam Tip: Understanding the `[row][column]` convention is fundamental. The first index always refers to the horizontal organization of data.

 

Question 41. In a two dimensional array, the second index specifies the …………… value.
(a) Column
(b) Row
(c) Both A and B
(d) None of the options
Answer: (a) Column
In simple words: In an expression like `array[X][Y]`, the second number, `Y`, always tells you which column the item is located in. This helps specify the exact position.

🎯 Exam Tip: Consistency in indexing (first row, then column) is crucial for correctly accessing and manipulating elements in 2D arrays.

 

Question 42. The two-dimensional array can be viewed as a …………………
(a) List
(b) Matrix
(c) Linear block
(d) None of the options
Answer: (b) Matrix
In simple words: A two-dimensional array can be thought of as a mathematical matrix. Both organize numbers into rows and columns, making them useful for similar tasks.

🎯 Exam Tip: Relating 2D arrays to matrices helps understand operations like matrix multiplication, addition, and transposition, which are directly applicable to 2D array manipulation.

 

Question 43. There are …………… types of 2-D array memory representations.
(a) two
(b) one
(c) three
(d) many
Answer: (a) two
In simple words: There are two main ways that a computer can arrange and store the items of a two-dimensional array in its memory. These are called row-major order and column-major order.

🎯 Exam Tip: While C/C++ typically use row-major order, understanding both representations is important for working with different programming languages or data structures.

 

Question 44. ……………… is a type of 2-D array memory representation.
(a) Row-Major order
(b) Column-Major order
(c) Either A or B
(d) None of the options
Answer: (c) Either A or B
In simple words: Two common methods for how two-dimensional arrays are organized in memory are row-major order and column-major order. Each method determines how elements are placed sequentially.

🎯 Exam Tip: Different programming languages adopt either row-major or column-major ordering. For example, C/C++ use row-major, while Fortran uses column-major.

 

Question 45. In row-major order, all the elements are stored ……………… in contiguous memory locations.
(a) Column by Column
(b) Row by Row
(c) Both A and B
(d) None of the options
Answer: (b) Row by Row
In simple words: In row-major order, the computer stores all the items of the first row next to each other in memory, then all the items of the second row, and so on. It arranges data row by row.

🎯 Exam Tip: Row-major order is the default for C++ arrays. This means iterating through elements row by row is generally more cache-friendly and faster.

 

Question 46. In column-major order, all the elements are stored ………………. in contiguous memory locations.
(a) Column by Column
(b) Row by Row
(c) Both A and B
(d) None of the options
Answer: (a) Column by Column
In simple words: When using column-major order, the computer stores all the items of the first column together in memory, then all the items of the second column, and so on. It stacks data column after column.

🎯 Exam Tip: While C++ uses row-major by default, understanding column-major is important when working with other languages or libraries that might use this convention.

 

Question 47. An array of strings is a ………………. dimensional character array,
(a) Two
(b) One
(c) Multi
(d) None of the options
Answer: (a) Two
In simple words: Since each string itself is an array of characters, an array that holds many strings becomes a two-dimensional array. One dimension is for the list of strings, and the other is for the characters within each string.

🎯 Exam Tip: When defining an array of strings like `char names[ROWS][COLS];`, the first dimension (`ROWS`) specifies the number of strings, and the second (`COLS`) specifies the maximum length of each string.

 

Question 48. In a two-dimensional character array, the size of the first index (rows) denotes the ……………….
(a) Maximum length of each string
(b) Number of strings
(c) Maximum characters
(d) None of the options
Answer: (b) Number of strings
In simple words: For a two-dimensional array used to store strings, the first number in the declaration (like `[X]` in `char array[X][Y]`) tells you how many individual strings you can store in that array. It represents the count of rows.

🎯 Exam Tip: Always remember that the first index for an array of strings indicates the quantity of strings, while the second index indicates the maximum length of each string.

 

Question 49. In a two-dimensional character array, the size of the second index (rows) denotes the ……………….
(a) Maximum length of each string
(b) Number of strings
(c) Maximum characters
(d) None of the options
Answer: (a) Maximum length of each string
In simple words: In a two-dimensional character array (which is like storing many strings), the second number in its size declaration (like `[Y]` in `char array[X][Y]`) tells you the longest possible length for any single string you store, including space for the null terminator.

🎯 Exam Tip: It's critical to allocate enough space for the maximum string length plus one byte for the null terminator (`\0`), otherwise, you risk buffer overflows.

 

Question 50. char Name[6][10]; How many strings can be stored in the above array?
(a) 10
(b) 60
(c) 6
(d) 16
Answer: (c) 6
In simple words: The array `char Name[6][10]` is designed to hold 6 strings. The first number `[6]` sets the total number of strings, and the second number `[10]` sets the maximum length of each string.

🎯 Exam Tip: In an array declaration like `type array_name[rows][columns];`, the `rows` value directly specifies how many individual strings or rows of data the array can hold.

 

Question 51. To pass an array to a function in C++, the function needs the ………….. as an argument,
(a) Array name
(b) Array type
(c) Dimension
(d) None of the options
Answer: (a) Array name
In simple words: When you want a function to work with an array, you typically just give it the array's name. The array name actually acts like a pointer to the first element of the array.

🎯 Exam Tip: When passing an array to a function, the array name decays into a pointer to its first element. It's often good practice to also pass the array's size as a separate argument.

Very Short Answers (2 Marks)

 

Question 1. What is the formula to calculate the memory space allocated for an array?
Answer: The memory space allocated for an array is calculated by multiplying the number of bytes required for one element's data type by the total number of elements in the array. This calculation helps determine the exact memory footprint of the array.
In simple words: To find an array's memory use, multiply the size of one item by the total number of items it holds.

🎯 Exam Tip: Always be aware of the memory size of each data type (e.g., `int` might be 2 or 4 bytes, `char` is 1 byte) when calculating array memory, as it can differ across compilers.

 

Question 2. What are the types of arrays?
Answer: In C++, arrays are used to store multiple values of the same type. There are different ways to organize these values, leading to various types of arrays:
1. One-dimensional arrays
2. Two-dimensional arrays
3. Multi-dimensional arrays
These types help store data in different layouts, from simple lists to complex grids.
In simple words: Arrays come in different forms to store data: one-dimensional (like a list), two-dimensional (like a table), and multi-dimensional (for more complex arrangements).

🎯 Exam Tip: Be ready to define each type and provide a simple example of when you would use each. For instance, a one-dimensional array for a list of scores, and a two-dimensional array for a spreadsheet.

 

Question 3. Write about returning structures from functions.
Answer: Structures, which group different data types, can be passed to functions either by copying their values (call by value) or by sending their memory address (call by reference). Just like regular variables, entire structure variables can also be sent back, or "returned," from a function. This allows functions to process and return complex, grouped data as a single unit.
In simple words: You can send an entire data structure to a function, and the function can also send a whole data structure back to you, just like passing simple numbers.

🎯 Exam Tip: When returning structures by value, a copy is made, which can be inefficient for large structures. Consider returning by reference or pointer for performance optimization if the structure is large.

 

Question 4. Write the syntax and example for one-dimensional declaration and initialization.
Answer: To create and give initial values to a one-dimensional array at the same time, you follow a specific pattern.
Syntax:
`datatype array_name[size] = {value-1, value-2, ..., value-n};`
Example:
`int age[5] = {19, 21, 16, 1, 50};`
This method makes the array ready to use immediately with predefined values.
In simple words: You make a 1D array by first saying what kind of data it holds, its name, and how many items it has in square brackets, then list the starting values in curly braces.

🎯 Exam Tip: Pay close attention to the use of square brackets `[]` for defining the array size and curly braces `{}` for enclosing the initial values. The `size` in `[]` can be omitted if all values are provided in `{}`.

 

Question 5. What is a global object?
Answer: Global objects are special objects that are created and declared right at the same time as their structure is defined. Once declared globally, these objects can be accessed and used from anywhere within the program. This means any function can use them without needing them to be passed as arguments.
In simple words: A global object is an object created with a structure that can be used by any part of the program, not just one function.

🎯 Exam Tip: While convenient, overuse of global objects can make programs harder to debug and maintain due to their wide accessibility. Use them sparingly and judiciously.

 

Question 6. Write a note on strings.
Answer: In C++, a string is typically a sequence of characters, which can include letters, numbers, or symbols. Each character in a string usually takes up one byte of memory. A key feature of C-style strings is that they are always ended by a special character called a null character (`\0`, which has an ASCII value of 0). This null character tells the program where the string finishes. The null character acts like a hidden stop sign for the string, helping functions know when to stop processing characters.
In simple words: Strings are lists of characters (like words or sentences). Each character takes 1 byte. C-style strings always end with a special null character (`\0`) to show where they stop.

🎯 Exam Tip: Always remember to account for the null terminator (`\0`) when allocating memory for C-style strings; a string of 'N' characters actually requires 'N+1' bytes of storage.

 

Question 7. Differentiate array and structure.
Answer: Here are the key differences between arrays and structures:
Array:
* An array is a collection of variables that are all of the same data type.
* Array data is accessed using an index number (e.g., `array[0]`, `array[1]`).
* Arrays usually allocate a fixed amount of memory (static memory) at compile time.
* Accessing individual array elements is generally very fast.
Structure:
* A structure is a collection of variables that can be of different data types.
* Structure elements are accessed using a dot (`.`) operator (e.g., `object.member`).
* Structures can allocate memory dynamically or statically depending on how they are used.
* Accessing structure elements using an operator might take slightly more time compared to direct array indexing.
Structures offer more flexibility for grouping related but varied data, whereas arrays are optimized for homogeneous collections.
In simple words: Arrays store many items of the *same* type and you find them with a number. Structures group items of *different* types, and you find their parts using a dot. Arrays use fixed memory, while structures can be more flexible.

🎯 Exam Tip: Remember that arrays are best for homogeneous data (e.g., a list of integers), while structures are perfect for heterogeneous data (e.g., a student record with name, age, and grade, which are different types).

Part – III

Short Answers

 

Question 1. Write about the initialization of 2 - D array.
Answer: A 2-D array can be given its starting values in more than one way when it is first created. For example, you can list all the values row by row, or just list them all in a continuous sequence. This flexibility helps in making the code cleaner and easier to read.

int matrix[4][3] = {
  {10,20,30},// Initializes row 0
  {40,50,60},// Initializes row 1
  {70,80,90},// Initializes row 2
  {100,110,120}// Initializes row 3
};
int matrix[4][3] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120};
For a 2-D array, it is always necessary to specify the number of columns, but the number of rows can sometimes be left out. This is because the compiler needs to know how many columns each row has to calculate memory correctly.
In simple words: You can set the first values of a 2-D array in different ways when you create it. You must always say how many columns it has, but not always how many rows.

🎯 Exam Tip: Remember to clearly show both methods of 2-D array initialization with appropriate examples to score full marks.

 

Question 2. What is subscript? Give its rules,
Answer: A subscript is a unique index number that helps to identify each item in an array. It always starts counting from 0. For example, in an array called `num`, `num[3]` refers to the fourth item because counting begins at zero.
Rules for subscript:

  • The subscript always starts with 0.
  • It should be a non-negative whole number.
  • Each element in an array is accessed using the array's name followed by its subscript index inside square brackets.

In simple words: A subscript is a number that tells you where an item is in an array, starting from 0. It must be a positive whole number.

🎯 Exam Tip: Emphasize that array indexing starts from 0 (zero-based indexing) as this is a fundamental concept often tested.

 

Question 3. How memory locations are allocated to a one-dimensional array?
Answer: Memory representation of a one-dimensional array: The amount of memory an array needs depends on its data type (like integer or character) and its size (how many items it holds). For example, if you have an integer array with 5 elements, and each integer takes 4 bytes in Dev C++ (or 2 bytes in Turbo C++), then the total memory allocated will be 20 bytes (or 10 bytes). This allocation is done in a continuous block of memory, making it efficient to access elements sequentially.
In simple words: An array stores all its items in a continuous block of memory. The total memory needed is figured out by multiplying how much space each item takes by the total number of items.

🎯 Exam Tip: Clearly state that arrays allocate contiguous memory, which is a key characteristic, and calculate total memory based on data type size and number of elements.

 

Question 4. Tabulate the memory requirement of data type in Turbo C++ and Dev C++.
Answer:

Data typeTurbo C++Dev C++
char11
int24
float44
long44
double88
long double1010
This table shows how different programming environments (Turbo C++ vs. Dev C++) might allocate different amounts of memory for the same data types, especially for `int`.
In simple words: This table shows how many bytes each basic data type (like `char`, `int`, `float`) needs for storage in two different C++ programs.

🎯 Exam Tip: Memorize the common byte sizes for basic data types in both Turbo C++ and Dev C++ as they can differ, particularly for `int`.

 

Question 5. Explain character Array (String) creation with syntax and example.
Answer: To create any array, its size (length) must be known in advance so that enough memory can be set aside. Once an array is made, its size cannot be changed later. This fixed size ensures that memory is used efficiently.
Syntax of array declaration:

char array_name[size];
In this declaration, the `size` must be an unsigned integer, meaning a whole number that is zero or positive.
For example:
char country[6];
This array sets aside 6 bytes of memory. It can store up to 5 characters, because one spot is always kept for the null character (`\0`) which marks the end of a string.
In simple words: When you make a character array (string), you first decide its size, and that size cannot change. It needs an extra spot for a special character that says "this is the end of the string."

🎯 Exam Tip: Always remember that C-style strings in C++ require an extra byte for the null terminator `\0`, so a `char array[N]` can store at most `N-1` actual characters.

 

Question 6. What is an array of strings?
Answer: An array of strings is like a two-dimensional character array. The first index (rows) tells you how many strings you can store, and the second index (columns) tells you the longest possible length for each string. Just like single strings, each string in an array of strings also needs a null character (`\0`) at its end. This special character helps the program know where each string finishes.
For example, a 2-D array might be declared as:

char Name[6][10];
In this example, `6` means there are 6 rows (or 6 strings), and `10` means each string can have a maximum length of 9 characters, with the 10th spot for the null character.
In simple words: An array of strings is a list where each item is a string. It's like a table where one side is for how many strings you have, and the other side is for how long each string can be.

🎯 Exam Tip: When declaring an array of strings, ensure the column size is large enough to accommodate the longest string plus its null terminator.

 

Question 7. Write note on getline( ) function.
Answer: In C++, the `getline()` function is very useful for reading a full line of text from the input, including any spaces. It keeps reading characters until it finds a newline character (when you press Enter) or a special delimiter character that you specify. This function is found in the `<string>` header file, which you need to include in your program. It makes it easy to capture user input that might contain spaces, unlike `cin >>` which stops at the first space.
In simple words: The `getline()` function in C++ reads a whole line of text, even with spaces, until it sees a new line or a stop sign you tell it to look for.

🎯 Exam Tip: Highlight that `getline()` is preferred over `cin >>` for reading strings with spaces, and remember to include the `<string>` header for its use.

 

Question 8. How memory represented for a 2-D array?
Answer: There are two main ways that memory is organized for a 2-D array:

  • Row Major order
  • Column Major order
These methods determine how the array elements are stored in a computer's single, continuous memory space. Understanding this helps in predicting memory access patterns and can influence program performance.
In simple words: A 2-D array stores its items in memory in two main ways: either all items from one row are stored together, then the next row, and so on (Row Major), or all items from one column are stored together, then the next column (Column Major).

🎯 Exam Tip: Define both Row Major and Column Major order clearly, as they represent fundamental ways 2-D arrays are laid out in memory, impacting how data is accessed.

 

Question 9. How 2-D character array initialized and stored in memory? Explain.
Answer: 2D character arrays, often used to store multiple strings, can be initialized by listing the strings directly. For instance, `char Name[6][10]` can hold 6 strings, each with a maximum length of 9 characters plus a null terminator. The memory stores these strings one after another in a continuous block. Each string occupies a fixed amount of space (the column size), even if it's shorter, to maintain a uniform structure.
For example:

char Name[6][10] = {"Mr. Bean", "Mr.Bush", "Nicole", "Kidman", "Arnold", "Jodie"};
In this example, the 2-D array is initialized with 6 strings. Each string can be up to 9 characters long, with the 10th space reserved for the null character (`\0`) which marks the end of each string. This memory arrangement means all the strings are stored in continuous locations, making it easy for the program to find them.
In simple words: You can set up a 2-D character array by giving it a list of names. It keeps each name in a block of memory, one after the other, and reserves space for a special end-of-name marker.

🎯 Exam Tip: When initializing 2-D character arrays with strings, always account for the null terminator (`\0`) at the end of each string in the column dimension to prevent buffer overflows.

 

Question 10. What is called nested structure? Give example.
Answer: A nested structure is simply a structure that is defined inside another structure. This allows you to group related data in a more organized and hierarchical way. The members of the inner structure can be accessed using the name of the parent structure, then the name of the child structure, followed by the member name. This helps in building complex data types from simpler ones.
Example:

struct Student
{
  int age;
  char month[3]; // Example of an inner structure member for month
  int year;
}; // Missing closing brace here in source, corrected for logic

struct dob // This struct is likely intended to be nested inside Student
{
  int date;
  char month[4];
  int year;
};
The example provided in the source is a bit fragmented, but if we assume `dob` is nested within `Student`:
struct Student
{
  int age;
  float height, weight;
  struct dob // Nested structure
  {
    int date;
    char month[4];
    int year;
  } birthDate; // Name for the nested structure object
};
Values can be assigned to this structure as follows:
// Assuming a 'Student' object named 'mahesh'
Student mahesh;
mahesh.birthDate.date = 25;
strcpy(mahesh.birthDate.month, "DEC");
mahesh.birthDate.year = 2017;

In simple words: A nested structure is like having a small box of things inside a bigger box. You can reach the items in the small box by first naming the big box, then the small box, then the item.

🎯 Exam Tip: When dealing with nested structures, always remember to access inner members using the dot operator multiple times (e.g., `outer_obj.inner_obj.member_name`).

 

Question 11. Write a program to pass an array as an argument to a function.
Answer: In C++, arrays can be sent to functions as arguments. When you pass an array to a function, the function only needs the array's name. This allows the function to work on the actual array data, rather than a copy. This method is efficient for large arrays because it avoids copying all the data.
C++ program to display marks of 5 students (one-dimensional array):

#include<iostream>
using namespace std;

void display (int m[5]); // Function prototype: declares the display function

int main( )
{
  int marks[5]={88, 76, 90, 61, 69}; // Initialize an array of marks
  display(marks); // Call the display function, passing the 'marks' array
  return 0;
}

void display (int m[5]) // Function definition: receives the array 'm'
{
  cout << "\nDisplay Marks: " << endl;
  for (int i=0; i<5; i++)
  {
    cout << "Student " << i+1 << ": " << m[i] << endl; // Display each student's mark
  }
}
Output
Display Marks:
Student 1: 88
Student 2: 76
Student 3: 90
Student 4: 61
Student 5: 69

In simple words: This program shows how to send a list of numbers (an array) to a function. The function then prints each number in the list.

🎯 Exam Tip: When passing an array to a function, only the array name is usually enough, and changes inside the function affect the original array because it's passed by reference (or pointer to its first element).

 

Question 12. Write a C++ program to pass a 2-D array to a function.
Answer: In C++, you can pass a two-dimensional array to a function. This is useful for processing tabular data like matrices. When you pass a 2-D array, the function must know the number of columns to correctly calculate memory addresses for elements. This ensures the function can properly access and manipulate the array's contents.
C++ program to display values from two dimensional array:

#include<iostream>
using namespace std;

void display (int n[3][2]); // Function prototype: specifies array dimensions

int main( )
{
  int num[3][2] = { {3, 4}, {9, 5}, {7,1} }; // Initialize a 3x2 2-D array
  display(num); // Call the display function
  return 0;
}

void display(int n[3][2]) // Function definition: receives the 2-D array
{
  cout << "\n Displaying Values" << endl;
  for (int i=0; i<3; i++) // Loop through rows
  {
    for (int j=0; j<2; j++) // Loop through columns
    {
      cout << n[i][j] << " "; // Print each element
    }
    cout << endl << endl; // Move to next line after each row
  }
}
Output
Displaying Values
3 4

9 5

7 1

In simple words: This program shows how to send a grid of numbers (a 2-D array) to a function. The function then prints all the numbers from the grid.

🎯 Exam Tip: When passing a 2-D array to a function, always ensure the function prototype and definition specify the number of columns, even if rows can be left unspecified for single-dimensional arrays.

 

Question 13. Write a user-defined function to return the structure after accepting value through the keyboard. The structure definition is as follows: struct Item{int item no; float price;};
Answer: You can create a function that takes an `Item` structure, fills its parts with values from the keyboard, and then sends the updated structure back. This makes it easy to collect data for different items. The function helps in keeping the code organized and reusable.
Here is the user-defined function:

item accept (item i) // Function 'accept' that takes and returns an 'item' structure
{
  cout << "\n Enter the Item No:"; // Prompt for item number
  cin >> i.no; // Read item number into 'i.no'
  cout << "\n Enter the Item Price:"; // Prompt for item price
  cin >> i.price; // Read item price into 'i.price'
  return i; // Return the updated 'item' structure
}

In simple words: This function asks you to type in an item's number and price. After you type them, it gives back the item details you just entered.

🎯 Exam Tip: When a function returns a structure, it's often a copy (pass by value). If you need to avoid copying large structures for performance, consider passing by reference.

 

Explain in Detail (5 Marks)

 

Question 1. How will you search an element in a one-dimensional array? Explain linear search.
Answer: Searching in a one-dimensional array is the process of finding a specific value within a list of numbers. One common method is linear search, also known as sequential search. This method works by checking each element in the array one by one, from the beginning to the end, until the desired value is found or all elements have been checked. It's like looking for a specific book on a shelf by checking every single book until you find the right one.
Program for Linear Search:

#include<iostream>
using namespace std;

// Function to search for a value in an array
int Search(int arr[ ], int size, int value)
{
  for (int i=0; i<size; i++) // Loop through each element
  {
    if (arr[i] == value) // If the current element matches the value
      return i; // Return its index
  }
  return -1; // If value is not found, return -1
}

int main( )
{
  int num[10], val, id; // Declare an array, a value to search, and an index variable
  for (int i=0; i<10; i++)
  {
    cout << "\n Enter value " << i+1 << "="; // Prompt user to enter values for the array
    cin >> num[i]; // Read value into array
  }
  cout << "\n Enter a value to be searched: "; // Prompt user to enter value to search
  cin >> val; // Read the value to search
  id = Search(num, 10, val); // Call the Search function
  if(id == -1)
  {
    cout << "\n Given value is not found in the array.."; // If Search returns -1, value not found
  }
  else
  {
    cout << "\n The value is found at the position " << id+1; // If found, print its position (index + 1)
  }
  return 0;
}
This program first gets values from the user to fill an array. Then, it asks for a value to search for. It uses the `Search()` function, which checks each item in the array. If the value is found, the function returns its position (index); otherwise, it returns -1.
In simple words: To search for something in a list (array), linear search checks each item one by one until it finds what it's looking for or reaches the end of the list.

🎯 Exam Tip: When explaining linear search, highlight its simplicity but also its inefficiency for large arrays compared to faster methods like binary search (if the array is sorted).

 

Question 2. Explain two-dimensional array with syntax and example.
Answer: A two-dimensional (2D) array is a collection of items of the same type, arranged in rows and columns, like a grid or a matrix. You can imagine it as a table where elements are stored in both height (rows) and width (columns). For example, a 3x3 matrix would have 3 rows and 3 columns. The key is that all elements are of the same data type.
2D array conceptual memory representation:

Column Subscript
Row Subscriptarr[0][0]arr[0][1]arr[0][2]
arr[1][0]arr[1][1]arr[1][2]
arr[2][0]arr[2][1]arr[2][2]

The array `arr` can be seen as a matrix with 3 rows and 3 columns. Since the subscript starts with 0, `arr[0][0]` refers to the very first element.
The syntax for declaring a 2-D array is:
data-type array_name[row-size][col-size];
In this declaration:
  • `data-type` refers to any valid C++ data type (like `int`, `float`, `char`).
  • `array_name` is the name given to the 2-D array.
  • `row-size` is the number of rows in the array.
  • `col-size` is the number of columns in the array.
For example:
int A[3][4];
In this example, `A` is a 2-D array with 3 rows and 4 columns. This array can store a maximum of \(3 \times 4 = 12\) elements.
In simple words: A 2-D array is like a table of similar items, organized into rows and columns. To create one, you say what kind of items it holds, its name, how many rows, and how many columns.

🎯 Exam Tip: Clearly distinguish between row and column indices. Emphasize that all elements in a 2-D array must be of the same data type, and its declaration syntax is crucial for allocating memory correctly.

Case Study

 

Question 1. Write a program to accept the marks of 10 students and find the average, maximum and minimum marks.
Answer: This program takes the marks of 10 students as input, then calculates and displays their total, average, highest, and lowest marks. It's a common task in programming to handle and analyze lists of numerical data like student scores.
PROGRAM

#include<iostream>
using namespace std;

int main( )
{
  int marks[10], sum=0, max, min; // Declare an array for 10 marks, sum, max, and min
  float avg; // Declare a float for average

  cout << "\n Enter Mark 1 ="; // Prompt for the first mark
  cin >> marks[0]; // Read the first mark
  max = marks[0]; // Initialize max with the first mark
  min = marks[0]; // Initialize min with the first mark

  for(int i=1; i<10; i++) // Loop for the remaining 9 marks
  {
    cout << "\n Enter Mark " << i+1 << "="; // Prompt for subsequent marks
    cin >> marks[i]; // Read mark into array
    sum = sum + marks[i]; // Add mark to sum

    if (marks[i] > max) // Check if current mark is greater than current max
      max = marks[i]; // Update max if true

    if (marks[i] < min) // Check if current mark is smaller than current min
      min = marks[i]; // Update min if true
  }

  avg = sum/10.0; // Calculate average (use 10.0 for float division)

  cout << "\n The Total Marks: " << sum; // Display total marks
  cout << "\n The Average Mark: " << avg; // Display average marks
  cout << "\n The Maximum Mark: " << max; // Display maximum mark
  cout << "\n The Minimum Mark: " << min; // Display minimum mark
  return 0;
}
Output (Example Values):
Enter Mark 1 =78
Enter Mark 2 =72
Enter Mark 3 =82
Enter Mark 4 =31
Enter Mark 5 =77
Enter Mark 6 =59
Enter Mark 7 =45
Enter Mark 8 =49
Enter Mark 9 =71
Enter Mark 10=38
The Total Marks: 602
The Average Mark: 60.2
The Maximum Mark: 82
The Minimum Mark: 31

In simple words: This program asks for 10 student scores, then calculates their sum, average, highest, and lowest scores.

🎯 Exam Tip: Initialize `max` with the smallest possible value and `min` with the largest possible value (or with the first array element) before the loop to ensure correct comparisons.

 

Question 2. Write a program to accept rainfall recorded in four metropolitan cities of India and find the city that has the highest and lowest rainfall.
Answer: This program is designed to collect rainfall data for a specified number of shops or cities (the problem statement says cities, but the code uses 'shop' as a variable name). It then identifies which shop/city has the highest and lowest product prices (or rainfall, based on the question context). This demonstrates how to use arrays to store related data and find extremes within that data.
PROGRAM

#include<iostream>
#include<string.h> // Required for strcpy
using namespace std;

int main( )
{
  int rate[10], min_rate, n; // Array for product rates, min rate, and number of shops/cities
  char shop[5][20]; // 2D array for shop/city names
  char minshop[20]; // To store the name of the shop/city with minimum rate

  cout << "\nHow many Shops: "; // Prompt for number of shops/cities
  cin >> n; // Read number of shops/cities

  for(int i=0; i<n; i++) // Loop to get details for each shop/city
  {
    cout << "\n Enter Name of the Shop " << i+1 << ": "; // Prompt for shop/city name
    cin >> shop[i]; // Read shop/city name
    cout << "\n Enter price of Product-X at " << shop[i] << ": "; // Prompt for product price
    cin >> rate[i]; // Read product price
  }

  min_rate = rate[0]; // Initialize min_rate with the first shop's rate
  strcpy(minshop, shop[0]); // Initialize minshop name with the first shop's name

  for(int i=1; i<n; i++) // Loop to find the minimum rate and corresponding shop
  {
    if (rate[i] < min_rate) // If current shop's rate is less than current minimum
    {
      min_rate = rate[i]; // Update minimum rate
      strcpy(minshop, shop[i]); // Update minimum shop name
    }
  }

  // The original problem asks for highest and lowest rainfall,
  // but the code finds lowest 'Proudct=X' cost. I will follow the code's logic.
  cout << "\n The Lowest cost of the Product-X at the " << minshop << " is " << min_rate; // Display the lowest cost and its shop
  // To find highest, similar logic would be used for 'max_rate' and 'maxshop'

  return 0;
}

In simple words: This program takes names of shops and prices of a product. It then finds which shop sells the product for the lowest price.

🎯 Exam Tip: When dealing with string manipulation (like copying names), always remember to include `<string.h>` and use functions like `strcpy()` instead of simple assignment to avoid errors.

Question (3) Survey your neighboring shops and find the price of any particular product of interest and suggest where to buy the product at the lowest cost.
Answer: This program asks for the names of different shops and the price of a specific product (Product-X) in each. It then compares all the prices to find the shop where Product-X costs the least. Finally, it tells you the name of the shop with the lowest price and that price. This helps find the best deal.
PROGRAM
#include<iostream>
#include<string.h>
using namespace std;
int main( )
{
int rate[10],min,n;
char shop[5][20];
char minshop[20];
cout<<"\nHow many Shops ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\nEnter Name of the Shop "<<i+1<<" :";
cin>>shop[i];
cout<<"\nEnter price of Product-X at "<<shop[i]<<" :";
cin>>rate[i];
}
min=rate[0];
strcpy(minshop,shop[0]);
for(int i=1;i<n;i++)
{
if (rate[i]<min)
{
min = rate[i];
strcpy(minshop,shop[i]);
}
}
cout<<"\n The Lowest cost of the Proudct=X at the " <<minshop <<"is"<<min;
}

In simple words: This code helps you find the cheapest price for a product across different shops. You enter shop names and prices, and it tells you which shop has the lowest price.

🎯 Exam Tip: When writing programs that involve comparing values like prices, remember to initialize your 'min' or 'max' variable with the first element's value before starting the loop for comparison.

 

Structures

 

Book Evaluation

 

Part -I

 

Choose The Correct Answer

 

Question 1. The data elements in the structure are also known as ……………..
(a) objects
(b) members
(c) data
(d) records
Answer: (b) members
In simple words: Inside a structure, the individual pieces of data you define are called members. These members hold the actual information for that structure.

🎯 Exam Tip: Remember that "members" is the key term for data elements within a structure, distinguishing them from elements in other data collections.

 

Question 2. Structure definition is terminated by ……………..
(a) :
(b) }
(c) ;
(d) ::
Answer: (c) ;
In simple words: Just like many statements in C++, a structure definition must end with a semicolon to tell the compiler it's complete.

🎯 Exam Tip: A missing semicolon after a structure definition is a very common syntax error; always double-check it.

 

Question 3. What will happen when the structure is declared?
(a) it will not allocate any memory
(b) it will allocate the memory
(c) it will be declared and initialized
(d) it will be only declared
Answer: (a) it will not allocate any memory
In simple words: When you declare a structure, you are just telling the computer what kind of data it will hold, but no memory is set aside until you create a variable of that structure type.

🎯 Exam Tip: Understand that a structure declaration is like a blueprint; memory is only reserved when you build an object (variable) from that blueprint.

 

Question 4. What is the out of this program?
#include<iostream>
#include<string.h>
using namespace std;
int main( )
{
struct student
{
int n;
char name[10];
};
students;
s.n = 123;
strcpy(s.name, β€œBalu”);
cout<<s.n;
co
ut<< s.name <<endl;
return 0;
}

Answer: (a) 123Balu
In simple words: This program tries to create a student record and print its number and name. Even with a typo in the `cout` statement, the numbers and name would print together, resulting in "123Balu".

🎯 Exam Tip: Pay close attention to variable names and object access (`students` vs `s` in this example), as small errors can lead to compilation issues or unexpected output. In C++, `cout << var1 << var2;` prints values consecutively without spaces or newlines unless explicitly added.

 

Question 5. A structure declaration is given below.
struct Time
{
int hours;
int minutes;
int seconds;
}t;

Using the above declaration which of the following refers to seconds.

(a) Time.seconds
(b) Time::seconds
(c) seconds
(d) t. seconds
Answer: (d) t. seconds
In simple words: To reach a specific part inside a structure, you must use the structure's variable name (here, 't') followed by a dot ('.') and then the member's name ('seconds'). This connects the variable to its particular data field.

🎯 Exam Tip: Always use the dot operator (`.`) with the structure variable name to access its members, for example, `object.member_name`.

 

Question 6. What will be the output of this program?
#include <iostream>
using namespace std;
struct ShoeType
{
string name; double price;
>; , β€˜ β€˜
int main()
{
ShoeType shoe1, shoe2;
shoe1.name = β€œAdidas”;
shoe1.price = 9.99;
cout<< shoe1.name<< ” #. β€œ<< shoe1.price<<endl;
shoe2 = shoe1;
shoe2.price = shoe2.price / 9;
cout<< shoe2.name<< ” # β€œ<< shoe2.price;
return 0;
}

(a) Adidas # 9.99 Adidas #1.11
(b) Adidas # 9.99 Adidas # 9.11
(c) Adidas # 9.99 Adidas # 11.11
(d) Adidas #9.11 Adidas # 11.11
Answer: (a) Adidas # 9.99 Adidas #1.11
In simple words: The program first prints the details of `shoe1` (Adidas # 9.99). Then, it copies `shoe1` to `shoe2`, changes `shoe2`'s price by dividing it by 9 (making it 1.11), and prints `shoe2`'s details (Adidas # 1.11). The program shows how structure variables can be copied and modified.

🎯 Exam Tip: When structures are assigned (`shoe2 = shoe1;`), all member values are copied. Be careful when performing calculations on copied members, as it only affects the copy.

 

Question 7. Which of the following is a properly defined structure?
(a) struct {int num;}
(b) struct sum {int num;}
(c) struct sum int sum;
(d) struct sum {int num;};
Answer: (d) struct sum {int num;};
In simple words: For a structure to be correctly defined in C++, it needs the `struct` keyword, an optional name (like `sum`), curly braces `{}` to hold its members, and a semicolon `;` at the very end. This tells the compiler it's a complete blueprint.

🎯 Exam Tip: Remember the basic syntax: `struct TagName { member_list };`. The semicolon at the end is crucial for a complete structure definition.

 

Question 8. A structure declaration is given below.
struct employee
{
int empno;
char ename[10];
} e[5];

Using the above declaration which of the following statement is correct.

(a) cout<<e[0].empno<<e[0].ename;
(b) cout<<e[0].empno<<ename;
(c) cout<<e[0]->empno<<e[0]->ename;
(d) cout<<e.empno<<e.ename;
Answer: (a) cout<<e[0].empno<<e[0].ename;
In simple words: This program defines an array of employee structures. To access a specific employee's details, like the first employee's number or name, you use the array index `e[0]` followed by a dot `.` and then the member name. This correctly targets the data you want to display.

🎯 Exam Tip: For an array of structures, first use the array index (`[0]`, `[1]`, etc.) to select the specific structure, then use the dot operator (`.`) to access its members.

 

Question 9. Which of the following cannot be a structure member?
(a) Another structure
(b) Function
(c) Array
(d) variable of double datatype
Answer: (b) Function
In simple words: A structure can hold different kinds of data like other structures, arrays, or basic variables, but it cannot contain functions directly as its members. Functions are behaviors, not data storage.

🎯 Exam Tip: Structures are data aggregates; they store data. Functions define behavior and are usually associated with classes or defined globally, not as direct members of a C-style structure.

 

Question 10. When accessing a structure member, the identifier to the left of the dot operator is the name of
(a) structure variable
(b) structure tag
(c) structure member
(d) structure-function
Answer: (a) structure variable
In simple words: When you use `variable.member` to get to a part of a structure, the `variable` part on the left of the dot is always the actual variable you created from that structure. This variable holds the data for that specific structure instance.

🎯 Exam Tip: The dot operator (`.`) always links a specific structure *variable* to one of its *members*. The structure *tag* (the blueprint name) is not used for direct member access.

 

Part – II

 

Very Short Answers

 

Question 1. Define structure. What is its use?
Answer: A structure is a special kind of data type made by the user. It can combine different types of data items into one single unit. This helps to group related information, even if it's of various types, and keep it together in one continuous block of memory.
In simple words: A structure lets you bundle different kinds of data (like numbers and text) into one neat package. This is helpful for keeping related information organized together.

🎯 Exam Tip: Emphasize that structures allow grouping *different* data types, which is their primary advantage over arrays that group only *same* data types.

 

Question 2. To store 100 integer numbers which of the following is good to use?
Array or Structure State the reason.

Answer: An Array is better to use for storing 100 integer numbers. An array is designed to hold many values of the *same* data type, referenced by a single name. A structure, on the other hand, is used when you need to combine variables of *different* data types into one unit. Since all 100 numbers are integers (the same type), an array is the most suitable and efficient choice. Using an array also helps save memory and makes searching faster compared to scattering individual variables in memory. Structures are good for complex data, but not for many items of the same type.
In simple words: Use an Array for 100 integer numbers. Arrays are for many items of the same type, making them perfect for this. Structures are for mixing different types of data, which is not needed here.

🎯 Exam Tip: Clearly state that arrays are for homogeneous data (same type), while structures are for heterogeneous data (different types). This distinction is key for choosing the right data type.

 

Question 3. What is the error in the following structure definition.
struct employee {inteno; charename[20]; char dept;} Employee e1,e2;

Answer: The error is that the structure definition `struct employee {inteno; charename[20]; char dept;}` is missing a semicolon at the end of its declaration, specifically after the closing curly brace `}`. Also, there are missing semicolons between the members `int eno; char ename[20]; char dept;`. The correct way to write it is to separate each member with a semicolon and end the structure definition with a semicolon. The variables `e1, e2` should also be declared outside the structure definition or correctly as a part of it, but `e1,e2` are being declared right after the closing brace. If variables are declared right after the structure definition, the structure tag name (`employee`) is optional. However, if the tag name is present, then `e1,e2` would be variables of `struct employee`.
Corrected version:
struct employee
{
int eno;
char ename[20];
char dept;
} e1,e2;

In simple words: The structure code has two main mistakes: semicolons are missing between the data items inside and also right after the closing curly brace of the structure. Every part of the structure definition needs to end with a semicolon.

🎯 Exam Tip: Always remember to put a semicolon after each member declaration inside a struct and also after the closing curly brace of the entire struct definition.

 

Question 4. Write a structure definition for the structure student containing exam no, name and an array for storing five subject marks.
Answer: Here is the correct structure definition for a student, including exam number, name, and an array to hold five subject marks:
Structure definition:
struct student
{
int examno;
char sname[30];
int mark [5];
};

In simple words: This code creates a blueprint called 'student'. Each student blueprint will hold their exam number (a whole number), their name (a short piece of text up to 30 characters), and a list of 5 numbers for their marks.

🎯 Exam Tip: Ensure that the array for marks (`int mark[5];`) is correctly sized to hold all required subject marks, and that the character array for the name (`char sname[30];`) is large enough for the name plus the null terminator.

 

Question 5. Why for passing a structure to a function call by reference is advisable to us?
Answer: Passing a structure to a function using "call by reference" is a good idea because it allows the function to make changes to the structure's contents, and these changes will be visible back in the main part of the program that called the function. If you pass by value, the function gets a copy, and any changes to that copy are not saved. Call by reference also helps save memory and makes the program run faster, especially for large structures, because it avoids making a full copy of the entire structure. Instead, only the memory address is passed.
In simple words: We pass structures by reference so that any changes made inside the function are saved and reflected in the original structure. It also uses less memory and runs faster because it avoids copying the whole structure.

🎯 Exam Tip: Highlight that call by reference enables data modification outside the function scope and improves performance by avoiding unnecessary data copying, especially for large data structures.

 

Question 6. What is the size of the following highlighted variable in terms of byte if it is compiled in dev C++
struct A{ float f[3]; char ch[5];long double d;};
struct B{ A a; int arr[2][3];}b[3]

Memory requirements (Using Dev C++):

Answer: The memory requirements for the given structures, when compiled in Dev C++, are calculated based on the standard sizes of data types. For `struct A`, `float` is 4 bytes, `char` is 1 byte, and `long double` is 16 bytes in Dev C++. For `struct B`, an `int` is 4 bytes.
Memory requirements (Using Dev C++):

VariableMemory requirement
float f[3];12 Bytes (3 * 4 bytes)
char ch[5];5 Bytes (5 * 1 byte)
long double d;16 Bytes (1 * 16 bytes)
A a; (Which is a structure variable)33 Bytes (12+5+16 bytes for float, char, long double respectively)
int arr[2][3];24 Bytes (2 * 3 * 4 bytes)
b[3] which is a structure variable of structure B171 Bytes (3 * (33 bytes for A + 24 bytes for int array))

Memory requirements (Using Turbo C++):
VariableMemory requirement
float f[3];12 Bytes (3 * 4 bytes)
char ch[5];5 Bytes (5 * 1 byte)
double d;10 Bytes (1 * 10 bytes)
A a; (Which is a structure variable)27 Bytes (12+5+10 bytes for float, char, double respectively)
int arr[2][3];12 Bytes (2 * 3 * 2 bytes)
b[3] which is a structure variable of structure B117 Bytes (3 * (27 bytes for A + 12 bytes for int array))

In simple words: We calculate the memory for each part of the structures by multiplying the number of items by the size of each item (e.g., a float is 4 bytes). Then, we add these up for each structure. The total memory for `b[3]` is found by multiplying the memory of one `struct B` by 3. The main difference between Dev C++ and Turbo C++ is the size of `int` and `long double`.

🎯 Exam Tip: Remember that data type sizes (especially for `int` and `long double`) can vary between different compilers (like Dev C++ and Turbo C++), so always specify the compiler version when calculating memory requirements.

 

Question 7. Is the following snippet is fully correct. If not identify the error.
Answer: No, the provided snippet is not fully correct. There are several errors in the code related to structure definitions and variable assignments. C++ requires strict syntax for structure declarations and operations. Below are the errors and their explanations:

StatementError
struct sum1 {int n1,n2;}s1;Missing semicolon after n1 and n2: `int n1; int n2;`
struct sum2 {int n1,n2}s2;Missing semicolon at the end of declaration statement; also missing semicolons for members.
cin>>s1.n1>>s1. n2;No Error (assuming correct semicolons in struct definition)
s2=s1;Objects of different structures cannot be directly copied. `s1` is of `sum1`, `s2` is of `sum2`.

In simple words: The code has mistakes. Each item inside a structure needs its own semicolon, and the structure itself must end with one. Also, you cannot copy data directly between two different types of structures.

🎯 Exam Tip: Ensure that structure members are separated by semicolons and that the structure definition itself ends with a semicolon. Also, remember that only structures of the exact same type can be assigned to each other directly.

 

Question 8. Differentiate array and structure.
Answer: Arrays and structures are both ways to group data, but they have key differences. An array is used to store many items of the *same* data type (like a list of only integers or only characters). For example, `int scores[10];` would hold 10 integer scores. The memory for array elements is always next to each other, which helps with quick access. However, if you need to store items of *different* data types together, an array cannot do this. If more than one variable is used, they can be stored in memory but not in adjacent locations. It increases the time consumption while searching. A structure, on the other hand, provides a way to group items of *different* data types into a single unit (like combining a student's name, age, and grade into one record). The structure ensures these different data types are stored together as one logical element, often in continuous memory. So, while an array is great for lists of similar items, a structure is perfect for creating complex records with varied information.
In simple words: Arrays store many items of the *same* kind (like a list of only numbers). Structures store items of *different* kinds together (like a person's name, age, and height). Arrays save memory when searching is not complex, but structures are better for mixed data types.

🎯 Exam Tip: Remember the fundamental distinction: arrays are for homogeneous collections, while structures are for heterogeneous collections. This helps determine which data type to use for specific programming problems.

 

Question 9. What are the different ways to initialize the structure members?
Answer: Structure members can be initialized in a couple of ways, similar to how regular variables or arrays are initialized. You can assign values to each member individually after declaring the structure variable, or you can initialize them directly when you declare the structure variable itself, using a list of values enclosed in curly braces.
Example:
Consider the following structure:struct Student
{
long int rollno;
int age;
float weight;
} balu ;

Here are two ways to initialize its members:
1. Individual Assignment:
`balu.rollno = 702016;`
`balu.age = 18;`
`balu.weight = 48.5;`
2. Direct Initialization (at declaration):
`balu = {702016, 18, 48.5};` (This assigns values in the order they are declared in the structure: rollno, age, then weight.)
In simple words: You can give starting values to a structure's parts in two main ways: either one by one after you create the structure variable, or all at once when you first make the structure variable by listing the values in curly braces.

🎯 Exam Tip: Direct initialization using curly braces `{}` is concise but requires values to be in the exact order of member declaration. Individual assignment offers more flexibility and clarity for specific member updates.

 

Question 10. What is wrong with the following C++ declarations?
Answer: The C++ declarations provided have several syntax errors, mainly related to missing semicolons, incorrect use of parentheses instead of curly braces, and improper placement of type specifiers. Each structure definition and member declaration must follow specific C++ rules for proper compilation. Below is a breakdown of the errors for each declaration:
A. struct point ( double x, y)
B. struct point { double x, double y >;
C. struct point { double x; double y >
D. struct point { double x; double y; };
E. struct point { double x; double y; >

Errors:
A. `struct point (double x, y)`
Structure definition must use curly braces `{}` to enclose its members and be terminated with a semicolon `;`. The members `x` and `y` also need their data type specified individually.
Correction: `struct point { double x; double y; };`
B. `struct point {double x, double y>;`
Structure member declarations should use semicolons `;`, not `>`. Each member needs its own type specified, `x` and `y` are two separate members of type `double`. Also, the structure definition itself needs to end with a semicolon.
Correction: `struct point { double x; double y; };`
C. `struct point {double x; double y >`
Similar to B, `>` is not a valid separator for members, and a semicolon is missing at the end of the structure definition. Each member needs its own data type and a semicolon.
Correction: `struct point { double x; double y; };`
D. `struct point {double x; double y;};`
This declaration is **correct**. It correctly uses curly braces for the structure body, separates members with semicolons, and ends the entire structure definition with a semicolon.
E. `struct point {double x; double y;>`
The structure definition is missing the final closing brace `}` and the terminating semicolon `;`.
Correction: `struct point { double x; double y; };`
In simple words: Many of the structure examples have small but important mistakes. They either use the wrong kind of brackets, forget to put a semicolon after each item inside, or forget the semicolon at the very end of the structure. The most important rule is to use curly braces and semicolons correctly for everything.

🎯 Exam Tip: Carefully check for curly braces `{}` enclosing members, semicolons `;` after each member declaration, and a semicolon `;` after the closing brace of the structure definition. These are common points of error.

Part - III

Short Answers

 

Question 1. How will you pass a structure to a function ?
Answer: A structure, which is like a custom data type, can be sent to a function just like any basic data type. There are two main ways to do this:
1. Call by value: When the whole structure is sent as an argument, this method is used.
2. Call by reference: When the memory address of the structure is sent as an argument, this method is used.
Call by value
When a structure is passed to a function using "call by value," any changes made to its content inside that function will not change the original structure outside the function. Think of it as sending a copy.
Call by reference
With "call by reference," the function receives the actual memory address of the structure using the '&' operator. This means any changes made to the structure's content inside the function *will* affect the original structure because the function is working directly on the original. This is like sending the original item.
In simple words: Structures can be sent to functions in two ways: by value (sending a copy, changes don't affect original) or by reference (sending the original's location, changes *do* affect original). When passing by reference, you use the '&' symbol.

🎯 Exam Tip: Remember that "call by value" passes a copy, ensuring the original data is protected, while "call by reference" passes the memory address, allowing the function to modify the original data.

 

Question 2. The following code sums up the total of all students name starting with β€˜S’ and display it. Fill in the blanks with required statements.
Answer: This C++ program collects details for 20 students, including their name, exam number, and marks in various subjects. It then calculates the total marks for each student. Finally, it displays the name and total marks for all students whose names begin with the letter 'S'.
cpp #includeusing namespace std; struct student { int exam_no,lang,eng,phy,che,mat,esc,total; char name[15]; }; int main( ) { student s[20]; for(int i=0;i<20;i++) { //accept student details cout<<"\nEnter student name"; cin>>s[i].name; cout<<"\nEnter student exam number"; cin>>s[i].exam_no; cout<<"\nEnter Languge Mark"; cin>>s[i].lang; cout<<"\nEnter Engjish Mark"; cin>>s[i].eng; cout<<"\nEnter Physics Mark"; cin>>s[i].phy; cout<<"\nEnter Chemistry Mark"; cin>>s[i].che; cout<<"\nEnter Maths Mark"; cin>>s[i].mat; cout<<"\nEnter Computer Science Mark"; cin>>s[i].csc; s[i].total = s[i].lang + s[i].eng + s[i].phy + s[i].che + s[i].mat + s[i].csc; } cout<<"\nDetails of student name starts with letter S "<In simple words: This program takes student information, calculates their total marks, and then shows the names and total marks of only those students whose names start with 'S'.

🎯 Exam Tip: Pay close attention to array indexing (starting from 0) and string comparison (`if(s[i].name[0] == 'S')`) when dealing with character arrays.

 

Question 3. What is called nested structure. Give example
Answer: A nested structure is a structure that is defined inside another structure. It works like a member of the outer structure, just as a normal variable would.
**Example:** cpp struct Student { int age; float height, weight; struct dob // 'dob' is a nested structure { int date; char month[4]; int year; }; // Semicolon is important here for struct dob }mahesh; In this example, `dob` is a nested structure within `Student`. Its members can be accessed using the parent structure's name, then the child structure's name, and finally the member's name. For instance, to access the `date` member of `dob` for the `mahesh` student, you would write `mahesh.dob.date`. This allows organizing related data hierarchically.
Here, `mahesh` is the variable (object) of the `Student` structure. `dob` is the name of the nested structure inside `Student`. `date` is a member variable inside the `dob` structure.
The structure can also be initialized directly: `dob = {25, "DEC", 2017};`
In simple words: A nested structure is a structure put inside another structure. You can reach its parts by first naming the main structure, then the nested one, and then the part you want, like `main_name.nested_name.part_name`.

🎯 Exam Tip: When working with nested structures, remember the dot operator (`.`) is used multiple times to navigate through the hierarchy: `parent_object.nested_structure_object.member`.

 

Question 4. Rewrite the following program after removing the syntactical error(s), if any.
Answer: The corrected C++ program declares a `movie` structure with members for movie name, language, and ticket cost. It then creates an object `Movie` of this structure. The program prompts the user to enter the movie's name, language, and ticket cost, and finally displays these details back to the user. Many syntactic errors from the original code have been fixed for proper execution.
cpp #include#include#includeusing namespace std; struct movie { char m_name[10]; char m_lang[10]; float ticket_cost; } Movie; int main( ) { cout << "\nEnter Movie Name: "; gets(Movie.m_name); cout << "\nEnter Movie Language: "; cin >> Movie.m_lang; cout << "\nEnter Ticket Cost: "; cin >> Movie.ticket_cost; cout << "\nMovie name is : " << Movie.m_name; cout << "\nMovie Language is : " << Movie.m_lang; cout << "\nTicket cost is : " << Movie.ticket_cost; return 0; }
In simple words: This program asks you to type in a movie's name, language, and how much a ticket costs. After you type it, the program shows you all that information back. It's a simple program to collect and show movie details.

🎯 Exam Tip: Always check for correct variable naming (no spaces or hyphens), proper use of semicolons, and the correct syntax for accessing structure members (using the dot operator). Remember to include necessary headers like `iostream` and `string.h`.

 

Question 5. What is the difference among the following two programs?
Answer: The primary difference between the two programs lies in how they initialize the members of a structure.
**Program 1:** cpp #include // Changed .h to standard iostream struct point { double x; double y; }; int main() { struct point test; // Declares a structure variable test.x = 0.25; // Initializes members individually using the dot operator test.y = 0.75; // cout << test.x << test.y; // Original line had OCR errors. This would print the values. return 0; }
**Program 2:** cpp #include // Assuming iostream header, original was empty struct Point // Fixed struct name from '.' to 'Point' { double x; double y; } Point_obj; // Renamed 'Point' object to 'Point_obj' to avoid conflict with struct name int main() { Point_obj test = {0.25, 0.75}; // Initializes all members at once using an initializer list return 0; } Program 1 initializes each member (`x` and `y`) separately after the structure variable `test` is declared, using the dot (`.`) operator. Program 2 uses an initializer list (`{0.25, 0.75}`) to assign values to all members of the `test` object during its declaration itself. Both methods achieve the same result but use different initialization techniques.
In simple words: The first program sets the structure parts one by one. The second program sets all the structure parts at the same time when it creates the structure. The core difference is how they give starting values to the structure's items.

🎯 Exam Tip: When initializing a structure, you can either assign values to members one by one or use an initializer list `{}` at the time of declaration for a more concise approach. Be careful with direct member access outside `main` if the object is local.

 

Question 6. How to access members of a structure? Give f example.
Answer: After declaring variables (objects) of a structure, you can access their individual members directly. You do this by using the dot operator (`.`) between the object's name and the member's name. This allows you to read or change the values stored in each part of the structure.
**Syntax:** `Object_name.Member_name`
**For example:** cpp struct Student { long rollno; int age; float weight; } balu, frank; // Declares two student objects: balu and frank To access the elements of the `Student` structure for `balu` and `frank`, you would use: * `balu.rollno` * `balu.age` * `balu.weight` * `frank.rollno` * `frank.age` * `frank.weight`
The dot operator helps to link a specific member to a specific structure variable.
In simple words: To get to a part of a structure, you write the structure's name, then a dot (.), and then the name of the part you want. For example, `student.age` would give you the student's age.

🎯 Exam Tip: The dot operator (`.`) is fundamental for accessing members of a structure. Ensure you use the correct object name before the dot and the correct member name after it.

 

Question 7. Write the syntax and an example for structure.
Answer: A structure is declared using the keyword `struct`. This keyword tells the compiler that you are defining a new custom data type that can hold different kinds of variables.
**Syntax for declaring a structure:** cpp struct structure_name { data_type member_name1; // The type and name of the first member data_type member_name2; // The type and name of the second member // ... more members can be added } object_name_list; // Optional: List of variables (objects) of this structure type The `object_name_list` is optional; you can declare structure variables later in your program.
**Example:** cpp struct Student { long rollno; // Student's roll number int age; // Student's age float weight; // Student's weight } balu, frank; // 'balu' and 'frank' are two variables of type Student In this example, `Student` is the name of the structure, and `balu` and `frank` are two different variables (also called objects) created using this `Student` structure template.
In simple words: You make a structure by using the `struct` word, then give it a name, and then list all the different types of information it will hold inside curly brackets `{}`. You can also make variables (like `balu`, `frank`) of this structure type right after the closing curly bracket.

🎯 Exam Tip: Remember that a structure definition ends with a semicolon after the closing curly brace, especially if you declare objects immediately after the definition.

 

Question 8. For the following structure, definition writes the user-defined function to accept data through the keyboard.
Answer: This user-defined function, `accept()`, is designed to gather input for an `item` structure from the keyboard. It creates a temporary `item` object, prompts the user for the item's ID, name, price, and the manufacturing date (day, month, year). After collecting all the data, it returns the filled `item` object.
cpp // Assuming necessary headers like and are included // and 'using namespace std;' is present for simplified cout/cin. // Given structure definitions: struct date { int dd, mm, yy; // Semicolon added at end of int dd,mm,yy; }; struct item { int item_id; // Fixed 'item id' to 'item_id' char name[10]; float price; date date_manif; }; // Semicolon added at end of struct item // User-defined function to accept data for an 'item' item accept() { item obj; // Create an 'item' object to store data cout << "\nEnter Item Id "; cin >> obj.item_id; // Fixed 'obj. item id' to 'obj.item_id' and 'cin> >' to 'cin >>' cout << "\nEnter Name "; cin >> obj.name; cout << "\nEnter Price "; cin >> obj.price; cout << "\nEnter Date: date, month and year (DD MM YYYY) "; // Added clear prompt for date format cin >> obj.date_manif.dd >> obj.date_manif.mm >> obj.date_manif.yy; return(obj); // Return the filled 'item' object }
In simple words: This function helps you put information into an `item` record. It asks for the item's ID, name, price, and its manufacturing date (day, month, year) one by one. Once you've typed everything, it gives you back the complete `item` record.

🎯 Exam Tip: When dealing with nested structures (like `date_manif` inside `item`), remember to use the dot operator multiple times to access the innermost members, e.g., `obj.date_manif.dd`.

 

Question 9. What is called an anonymous structure? Give an example.
Answer: An anonymous structure is a structure that is declared without a specific name or tag. Instead of defining the structure separately and then creating variables of that type, the structure's definition is directly associated with the declaration of its variables.
**Example:** cpp struct // No name given to the struct here, making it anonymous { long rollno; int age; float weight; } student; // 'student' is the variable (object) of this anonymous structure In this example, the structure itself has no name, but the variable `student` is created directly from its definition. This `student` variable can then be used to access the structure's members, such as `student.rollno`, `student.age`, and `student.weight`. Anonymous structures are useful when you only need one or a few variables of that specific structure type and don't plan to reuse the structure definition elsewhere.
In simple words: An anonymous structure is a structure that doesn't have its own name. You just make the structure and immediately give it a variable name (like `student`). You use this variable to reach its parts, like `student.age`.

🎯 Exam Tip: Anonymous structures are declared without a tag name between the `struct` keyword and the opening curly brace. This means you can only create variables of this structure type at the point of definition.

 

Question 10. Write a user-defined function to return the structure after accepting value through the keyboard. The structure definition is as follows: struct Item{int item no;float price;};
Answer: This user-defined function, `accept()`, is designed to collect data for an `Item` structure from the keyboard and then return the populated `Item` object. It prompts the user to enter the item's number and its price.
cpp // Assuming necessary headers like are included // and 'using namespace std;' is present. // Structure definition as given in the question: struct Item { int item_no; // Fixed 'item no' to 'item_no' float price; }; // Semicolon added here // User-defined function to accept data for an 'Item' Item accept() { Item obj; // Create an 'Item' object cout << "\nEnter Item Number and Price: "; // Fixed prompt text and removed stray comma cin >> obj.item_no >> obj.price; // Fixed input for item number and price return obj; // Return the filled 'Item' object (parentheses around obj are optional) }
In simple words: This function takes in details for an `Item` like its number and price from the keyboard. It then gives back the whole `Item` record filled with these details.

🎯 Exam Tip: Ensure that the structure definition ends with a semicolon. When reading multiple inputs on one line, separate `cin` operations with `>>` for each variable.

Part - IV

Explain In Detail

 

Question 1. Explain the array of structures with examples.
Answer: An array of structures is a powerful way to manage multiple records of the same type. For instance, if you have a class with many students, instead of creating a separate structure variable for each student, you can use an array of a single `Student` structure. This allows you to store details for all students efficiently, just like a regular array stores multiple values of a basic data type.
**Example:**
This C++ program demonstrates how to use an array of structures to read and then display the details (age, height, weight) for 20 students.
cpp #includeusing namespace std; struct Student { int age; float height, weight; char name[30]; // Added to make the example more complete, though not used in the input loop. }; int main() // Changed 'void main()' to standard 'int main()' { Student std_array[20]; // Renamed to avoid conflict with standard library 'std' int i; cout << "Enter the details for 20 students" << endl; for(i=0; i<20; i++) { cout << "\nEnter the details of student " << i+1 << endl; // Added newline for clarity cout << "Enter the age: "; // Prompt for age cin >> std_array[i].age; // Corrected variable name cout << "Enter the height: "; // Prompt for height cin >> std_array[i].height; // Corrected variable name cout << "Enter the weight: "; // Prompt for weight cin >> std_array[i].weight; // Corrected variable name } cout << "\nThe values entered for Age, height and weight are:\n"; // Added newline and clarified text for(i=0; i<20; i++) { cout << "Student " << i+1 << "\t" // Using '\t' for tab spacing<< std_array[i].age << "\t"<< std_array[i].height << "\t"<< std_array[i].weight << endl; // Added endl for new line after each student's data } return 0; // Added return 0 for int main() } This program creates an array `std_array` that can hold 20 `Student` structures. It then uses loops to go through each `Student` object in the array, asking for their details and then showing them. This shows how useful an array of structures is for managing many similar data records.
In simple words: An array of structures is like having a list where each item in the list is a full record (a structure). This helps to easily store and handle information for many similar things, like all the students in a class, in an organized way.

🎯 Exam Tip: When using an array of structures, remember to access individual members using array indexing (`std_array[i]`) followed by the dot operator (`.`) and the member name (`.age`).

 

Question 2. Explain call by value with respect to structure.
Answer: "Call by value" is a method where a copy of a structure variable is passed to a function as an argument. This is similar to how basic data types (like `int` or `char`) are passed. When you pass a structure by value, the function works on a separate copy of the structure. Therefore, any changes made to the structure's contents inside that function will not affect the original structure variable in the calling part of the program. The original data remains unchanged.
**Example:**
This C++ program demonstrates passing an `Employee` structure by value. The `printData` function receives a copy of the `Employee` structure. Any operations within `printData` will not alter the original `Employee` object in `main`.
cpp #includeusing namespace std; struct Employee { char name[50]; int age; float salary; }; void printData(Employee); // Function declaration: takes Employee by value int main() { Employee p; // Create an Employee object cout << "Enter Full name: "; cin.getline(p.name, 50); // Using cin.getline for names with spaces cout << "Enter age: "; cin >> p.age; cout << "Enter salary: "; cin >> p.salary; printData(p); // Call function, passing 'p' by value (a copy is sent) return 0; } // Function definition: receives a copy of Employee as 'q' void printData(Employee q) { cout << "\nDisplaying Information." << endl; cout << "Name: " << q.name << endl; cout << "Age: " << q.age << endl; cout << "Salary: " << q.salary << endl; } In this example, when `printData(p)` is called, a copy of `p` (named `q` inside the function) is made. `printData` then works with `q`. If `printData` were to change `q.age`, the `p.age` in `main` would remain the same.
In simple words: "Call by value" means you send a copy of a structure to a function. The function can play with this copy all it wants, but the original structure back in the main program stays exactly the same.

🎯 Exam Tip: When a structure is passed by value, a new copy of the entire structure is created. This ensures data protection but can be less efficient for very large structures due to memory overhead and copying time.

 

Question 3. How call by reference is used to pass structure to a function .Give an Example
Answer: In C++, structures can be passed to functions just like regular data types. There are two main ways to do this: "call by value" and "call by reference." When you use **call by value**, a copy of the structure is sent to the function. This means any changes made to the structure inside the function will not affect the original structure outside of it. The original data remains safe and unchanged. For **call by reference**, instead of copying the whole structure, its memory address is passed to the function using the ampersand (\( \& \)) operator. This allows the function to work directly on the original structure, so any changes made inside the function will affect the original data. This method is often preferred for large structures because it saves memory and is faster since no large copies are made.
**Example:** cpp #includeusing namespace std; struct Employee { char name[50]; int age; float salary; }; void readData(Employee &); // Function declaration for call by reference void printData(Employee); // Function declaration for call by value int main() { Employee p; readData(p); // Call by reference to get input printData(p); // Call by value to display return 0; } void readData(Employee &p) // Function to read employee data (call by reference) { cout << "Enter Full name: "; cin.get(p.name, 50); cout << "Enter age: "; cin >> p.age; cout << "Enter salary: "; cin >> p.salary; } void printData(Employee p) // Function to print employee data (call by value) { cout << "\nDisplaying Information." << endl; cout << "Name: " << p.name << endl; cout << "Age: " << p.age << endl; cout << "Salary: " << p.salary << endl; } **Output:** Enter Full name: Kumar Enter age: 55 Enter salary: 34233.4 Displaying Information. Name: Kumar Age: 55 Salary: 34233.4 In this program, `readData` uses call by reference to modify the `Employee` structure `p` directly, while `printData` uses call by value to display a copy of `p`, ensuring the original `p` remains unchanged by `printData`. Passing by reference is usually better for large structures as it saves memory and executes faster.
In simple words: Passing a structure by reference means the function works directly on the original data, so any changes stay. Passing by value sends a copy, so the original data remains untouched. Reference is faster for big structures.

🎯 Exam Tip: Always consider the size of the structure and whether you need to modify the original data when choosing between call by value and call by reference. For large structures that need modification, call by reference is more efficient.

 

Question 4. Write a C++ program to add two distances using the following structure definition
Answer: Here is a C++ program that uses a `struct Distance` to add two distances, each given in feet and inches. cpp #includeusing namespace std; struct Distance { int feet; float inch; } d1, d2, sum; // Declaring three structure variables int main( ) { cout << "\nEnter distance 1: feet and inch : "; cin >> d1.feet >> d1.inch; cout << "\nEnter distance 2: feet and inch : "; cin >> d2.feet >> d2.inch; // Add inches first sum.inch = d1.inch + d2.inch; // Convert inches to feet if sum.inch is 12 or more sum.feet = d1.feet + d2.feet + (int)(sum.inch / 12); sum.inch = sum.inch - ((int)(sum.inch / 12) * 12); // Keep remaining inches cout << "\nDistance 1: Feet = " << d1.feet << " Inch = " << d1.inch; cout << "\nDistance 2: Feet = " << d2.feet << " Inch = " << d2.inch; cout << "\nSum of Distance 1 and 2 : Feet = " << sum.feet << " Inch = " << sum.inch; return 0; } **Output:** Enter distance 1: feet and inch : 3 8.5 Enter distance 2: feet and inch : 2 6.5 Distance 1: Feet = 3 Inch = 8.5 Distance 2: Feet = 2 Inch = 6.5 Sum of Distance 1 and 2 : Feet = 6 Inch = 3 This program creates a structure `Distance` with `feet` (integer) and `inch` (float) members. It takes two distances as input, adds their feet and inches separately, and then adjusts the inches if they exceed 12, adding the extra to the feet. The result is a total distance in a simplified feet and inches format.
In simple words: This program takes two measurements of length (feet and inches) and adds them up. If the total inches are more than 12, it converts some inches into extra feet, so the final answer is always shown with less than 12 inches.

🎯 Exam Tip: When adding measurements like feet and inches, remember to handle units correctly by converting excess smaller units (inches) into larger units (feet) by dividing by the conversion factor (12 for inches to feet).

 

Question 5. Write a C++ Program to Add two Complex Numbers by Passing Structure to a Function for the following structure definition
Answer: Here is a C++ program that defines a `complex` structure and uses a function to add two complex numbers by passing the structure by value. cpp #includeusing namespace std; struct complex { float real; float imag; }; // Function prototype: returns a complex number, takes two complex numbers complex addComplexNumbers(complex obj1, complex obj2) { complex obj3; obj3.real = obj1.real + obj2.real; // Add the real parts obj3.imag = obj1.imag + obj2.imag; // Add the imaginary parts return(obj3); } int main( ) { complex c1, c2, c3; cout << "\nEnter First complex number real and imaginary :"; cin >> c1.real >> c1.imag; cout << "\nEnter Second complex number real and imaginary :"; cin >> c2.real >> c2.imag; // Call the function to add the complex numbers c3 = addComplexNumbers(c1, c2); cout << "\nFirst Complex Number is : " << c1.real << " + " << c1.imag << "i"; cout << "\nSecond Complex Number is : " << c2.real << " + " << c2.imag << "i"; cout << "\nAdded Complex Number is : " << c3.real << " + " << c3.imag << "i"; return 0; } **Output:** Enter First complex number real and imaginary :3 5 Enter Second complex number real and imaginary :4 2 First Complex Number is : 3 + 5i Second Complex Number is : 4 + 2i Added Complex Number is : 7 + 7i This program uses a `complex` structure to hold the real and imaginary parts of a complex number. It defines a function `addComplexNumbers` which takes two complex numbers (passed by value) and returns their sum as a new complex number. The `main` function gets two complex numbers from the user, calls `addComplexNumbers` to sum them up, and then displays the result. Complex numbers are useful in many fields like electrical engineering and physics.
In simple words: This program helps add two special numbers called complex numbers. You give the real and imaginary parts of two complex numbers, and the program adds them together, giving you a new complex number.

🎯 Exam Tip: When dealing with complex numbers, remember to add the real parts separately and the imaginary parts separately. The `i` in `a + bi` represents the imaginary unit.

 

Question 6. WrIte a C++ Program to declare a structure book containing name and author as character array of 20 elements each and price as Integer. Declare an array of book. Accept the name, author, price detail for each book. Define a user defined function to display the book details and calculate the total price. Return total price to the calling function.
Answer: Here is a C++ program that defines a `book` structure to store book details (name, author, price). It then uses an array of these structures to manage multiple books. A function `display` is used to show book details and calculate the total price of all books, returning this total to the `main` function. cpp #include#include // For formatting output #include // For string manipulation functions like strcpy using namespace std; struct book { char bname[20], author[20]; int price; }; // Function to display book details and calculate total price int display(book x[5]) // Accepts an array of 5 book structures { int total = 0; for(int i = 0; i < 5; i++) { total = total + x[i].price; // Add current book's price to total cout << "\nBook name : " << x[i].bname; cout << "\nAuthor name : " << x[i].author; cout << "\nPrice of the book: " << x[i].price; } return total; // Return the calculated total price } int main( ) { book b[5]; // Declare an array of 5 book structures // Loop to get details for 5 books from the user for(int i = 0; i < 5; i++) { cout << "\nEnter Book name "; cin >> b[i].bname; // Using cin for char array, be careful with spaces cout << "\nEnter Author name "; cin >> b[i].author; // Using cin for char array cout << "\nEnter Book Price "; cin >> b[i].price; } cout << "\nDetails of Books" << endl; // Call display function and print the total cost cout << "\nTotal cost of the book is : Rs." << display(b); return 0; } **Output:** Enter Book name Programming Enter Author name Dromy Enter Book Price 300 Enter Book name C++Programming Enter Author name BjarneStroustrup Enter Book Price 500 Enter Book name DataStructures Enter Author name Thomas Enter Book Price 450 Enter Book name Algorithms Enter Author name Cormen Enter Book Price 600 Enter Book name OS Enter Author name Tanenbaum Enter Book Price 350 Details of Books Book name : Programming Author name : Dromy Price of the book: 300 Book name : C++Programming Author name : BjarneStroustrup Price of the book: 500 Book name : DataStructures Author name : Thomas Price of the book: 450 Book name : Algorithms Author name : Cormen Price of the book: 600 Book name : OS Author name : Tanenbaum Price of the book: 350 Total cost of the book is : Rs.2200 This program helps manage information for several books. It collects the name, author, and price for each book. Then, it shows all the book details and calculates the total cost if you buy all of them. This is useful for keeping a simple inventory or creating a shopping list. Note that `cin >> char_array` stops reading at the first whitespace, so for names with spaces, `cin.getline()` would be more appropriate for `bname` and `author`.
In simple words: This program stores details like name, author, and price for five books. It then shows all these details and adds up the prices to give you the total cost for all the books.

🎯 Exam Tip: When using character arrays with `cin >>`, remember that it stops reading at whitespace. For inputting names with spaces, use `cin.getline(variable_name, size)` instead to capture the full line.

 

Question 7. Write a C++ program to declare and accept an array of professors. Display the details of the department=”COMP.SCI” and the name of the professors start with β€˜A’. The structure β€œcollege” should contain the following members.
prof-id as integer ,
name and Department as character array
Answer: Here is a C++ program that uses a structure named `college` to store information about professors, including their ID, name, and department. The program then takes details for five professors and displays only those who belong to the "COMP.SCI" department and whose names start with the letter 'A'. cpp #include#include // For formatting output #include // For string comparison (strcmp) using namespace std; struct college { char pname[20], department[20]; int prof_id; }; // Function to display details of professors based on criteria void display(college x[5]) { for(int i = 0; i < 5; i++) { // Check if department is "COMP.SCI" and professor's name starts with 'A' if((strcmp(x[i].department, "COMP.SCI") == 0) && (x[i].pname[0] == 'A')) cout << x[i].pname << endl; // Print the name if both conditions are true } return; } int main( ) { college c[5]; // Declare an array of 5 college structures // Loop to accept details for 5 professors for(int i = 0; i < 5; i++) { cout << "\nEnter Professor Name "; cin >> c[i].pname; cout << "\nEnter Department Name "; cin >> c[i].department; cout << "\nEnter Professor Id "; cin >> c[i].prof_id; } cout << "\nDetails of Comp. Sci. Dept, Professors whose name starts. with A " << endl; display(c); // Call the display function return 0; } **Output:** Enter Professor Name Amit Enter Department Name COMP.SCI Enter Professor Id 101 Enter Professor Name Bhavna Enter Department Name MATH Enter Professor Id 102 Enter Professor Name Anil Enter Department Name COMP.SCI Enter Professor Id 103 Enter Professor Name Zara Enter Department Name BIO Enter Professor Id 104 Enter Professor Name Ali Enter Department Name COMP.SCI Enter Professor Id 105 Details of Comp. Sci. Dept, Professors whose name starts. with A Amit Anil Ali This program allows you to enter information for several professors. It then filters this information and shows only the names of professors who work in the Computer Science department and whose names begin with 'A'. This type of filtering is useful for quickly finding specific data within a larger set.
In simple words: This program takes details of professors. It then finds and prints the names of only those professors who are in the "COMP.SCI" department and whose names start with 'A'.

🎯 Exam Tip: When using `strcmp()` for string comparison in C++, remember it returns 0 if the strings are identical. For checking the first character, access it like an array element: `x[i].pname[0] == 'A'`. Ensure consistent case for comparison or convert to a common case (e.g., uppercase) before comparing.

 

Question 8. Write the output of the following C++ program
Answer: Here is the C++ program and its expected output. The program defines a structure for `books` and then uses `strcpy` to assign specific names and authors to two book objects within an array, `a[0]` and `a[1]`. It then prints these details along with a formatted header. cpp #include#include // For gets, puts #include // For strcpy #include // For clrscr, getch (if using Turbo C++) using namespace std; struct books { char name[20], author[20]; } a[50]; // Declaring an array of 50 book structures int main ( ) { // clrscr(); // specific to Turbo C++ for clearing screen cout << "Details of Book No " << 1 << "\n"; cout << "---------------\n"; cout << "Book Name :" << strcpy(a[0].name, "Programming ") << endl; cout << "Book Author :" << strcpy(a[0].author, "Dromy") << endl; cout << "\nDetails of Book No " << 2 << "\n"; cout << "---------------\n"; cout << "Book Name :" << strcpy(a[1].name, "C++programming" ) << endl; cout << "Book Author :" << strcpy(a[1].author, "BjarneStroustrup ") << endl; cout << "\n\n"; cout << "======================\n"; cout << "S.No\t| Book Name\t|author\n"; cout << "======================\n"; for (int i = 0; i < 2; i++) { cout << (i + 1) << "\t|" << a[i].name << "\t|" << a[i].author << endl; } cout << "======================\n"; // getch(); // specific to Turbo C++ to hold screen return 0; } **Output:** Details of Book No 1 --------------- Book Name :Programming Book Author :Dromy Details of Book No 2 --------------- Book Name :C++programming Book Author :BjarneStroustrup ====================== S.No | Book Name |author ====================== 1 |Programming |Dromy 2 |C++programming |BjarneStroustrup ====================== The program initializes two book records using `strcpy` to copy strings into the `name` and `author` fields. It then prints the details of these two books, first individually, and then in a formatted table. The use of `\t` (tab) creates spacing for the table columns. Notice how `strcpy` returns a pointer to the destination string, which `cout` then prints.
In simple words: This program sets up information for two books, including their names and authors. It then prints out these details in a simple list and also in a neatly arranged table.

🎯 Exam Tip: Remember that `strcpy()` is used to copy one string to another character array. `endl` adds a newline and flushes the buffer, while `\n` just adds a newline. Be mindful of trailing spaces in strings copied by `strcpy` as they will be included in the output.

 

Question 9. Write the output of the following C++ program
Answer: Here is the C++ program and its expected output. The program defines a `student` structure with roll number, name, and phone number. It then initializes one student (`p1`) and assigns values to two other students (`p2`, `p3`) using direct assignment and `strcpy`. Finally, it prints the details for all three students in a specific order. cpp #include#include // For strcpy using namespace std; struct student { int roll_no; char name[10]; long phone_number; }; int main() { student p1 = {1, "Brown", 123443}; // Initialize student p1 student p2, p3; // Declare students p2 and p3 p2.roll_no = 2; strcpy(p2.name, "Sam"); // Assign name to p2 p2.phone_number = 1234567822; p3.roll_no = 3; strcpy(p3.name, "Addy"); // Assign name to p3 p3.phone_number = 1234567844; cout << "First Student" << endl; cout << "roll no : " << p1.roll_no << endl; cout << "name : " << p1.name << endl; cout << "phone no : " << p1.phone_number << endl; cout << "Second Student" << endl; cout << "roll no : " << p2.roll_no << endl; cout << "name : " << p2.name << endl; cout << "phone no : " << p2.phone_number << endl; cout << "Third Student" << endl; cout << "roll no : " << p3.roll_no << endl; cout << "name : " << p3.name << endl; cout << "phone no : " << p3.phone_number << endl; return 0; } **Output:** First Student roll no : 1 name : Brown phone no : 123443 Second Student roll no : 2 name : Sam phone no : 1234567822 Third Student roll no : 3 name : Addy phone no : 1234567844 This program creates three student records using a `student` structure. It sets the roll number, name, and phone number for each. Then, it neatly prints all these details for the first, second, and third students. This demonstrates how to store and display organized information for multiple individuals using structures. Initializing `p1` using `{}` is a convenient way to set all member values at once.
In simple words: This program stores and shows the roll number, name, and phone number for three different students. It prints all this information clearly for each student.

🎯 Exam Tip: When using aggregate initialization for structures (e.g., `student p1 = {1, "Brown", 123443};`), ensure the values are provided in the exact order of the structure members. For character arrays, `strcpy` is necessary to assign string values after declaration.

 

Question 10. Debug the error in the following program.
Answer: The provided program snippet contains several syntactical and logical errors. It is important to fix these to ensure the program compiles and runs correctly. Fixing errors helps coders learn precise syntax.

StatementError
struct sum1 {int n1,n2;}s1;No Error
struct sum2 {int n1,n2}s2;Semicolon missing at the end of declaration statement;
cin>>s1.n1>>s1. n2;No Error
s2-s1;Objects of different structures cannot be directly copied.
In simple words: The original code had some small mistakes, like missing semicolons or wrong spacing. It also tried to copy two different types of structures directly, which is not allowed. The fixed code corrects these issues.

🎯 Exam Tip: Pay close attention to semicolons after structure definitions and correct spacing in declarations. Remember that direct assignment between structures only works if they are of the exact same type.

 

Question 10. Debug the error in the following program.
Answer: Here are the errors in the program and their corrections. Identifying and fixing these errors makes the program functional and reliable.

Error LocationCorrection
#include Replace istream.h with iostream.h
struct PersonRecNo space between struct and PersonRec
char lastName[10];No space after char
chaefirstName[10];No space after char and spelling mistake (chae should be char)
int age;}Semicolon missing after int age, should be int age;};
PersonRecPeopleArrayType[10];Space missing after structure name PersonRec
void LoadArray(PeopleRecpeop);Structure name (PersonRec) is wrongly given, parameter should be PeopleRec peop[10]
Array Index MissingArray index is missing in people.firstName, people.lastName, people.age
Function ParameterSpace after structure name is missing, and array size is also missing in void LoadArray(PersonRecpeop)
Array Name in cinArray name is wrongly given as peop[i].age;←

MODIFIED PROGRAM
#include<iostream.h>
struct PersonRec
{
char lastName[10];
char firstName[10];
int age;
};
PersonRec PeopleArrayType[10];
void LoadArray(PersonRec peop[10]);
void main( )
{
PersonRec people[10];
for (int i = 0; i < 10; i++)
{
cout << people[i].firstName << " " << people[i].lastName << setw(10)
<< people[i].age;
}
}
LoadArray(PersonRec peop[10])
{
for (int i = 0; i < 10; i++)
{
cout << "Enter first name: ";
cin >> peop[i].firstName;
cout << "Enter last name: ";
cin >> peop[i].lastName;
cout << "Enter age: ";
cin >> peop[i].age;
}
}
In simple words: The original program had many mistakes in how it declared structures, used includes, and passed arrays to functions. The fixed code corrects these errors by using the right include files, properly defining structures with correct spacing and semicolons, and making sure array elements are accessed correctly using indices.

🎯 Exam Tip: When debugging C++ programs, always check header files, proper syntax for structure declarations (including semicolons), and correct array indexing, especially when passing arrays to functions. Use setw() from iomanip for formatted output.

11th Computer Science Guide Arrays and Structures Additional Questions and Answers

Choose The Correct Answer 1 Mark

 

Question 1. …………….. is a user-defined which has the combination of data items with different data types.
(a) Structure
(b) Class
(c) Union
(d) Array
Answer: (a) Structure
In simple words: A structure is a special kind of data type you create yourself. It helps you group together different kinds of information, like a name (text) and an age (number), all under one single name.

🎯 Exam Tip: Remember that structures are used for grouping *heterogeneous* data (different types), while arrays are for *homogeneous* data (same type).

 

Question 2. …………………. allows to group of variables of mixed data types together into a single unit.
(a) Structure
(b) Class
(c) Union
(d) Array
Answer: (a) Structure
In simple words: A structure lets you collect various types of data, like a mix of numbers and letters, and treat them as one single item. This helps keep related information organized.

🎯 Exam Tip: Understand that this question reinforces the core definition of a structure – its ability to combine different data types into one logical unit.

 

Question 3. If the elements are of different data types,then ……………… cannot support.
(a) Structure
(b) Class
(c) Union
(d) Array
Answer: (d) Array
In simple words: An array can only hold items that are all of the same kind. So, if you have different types of data, an array cannot store them together.

🎯 Exam Tip: This highlights a key limitation of arrays: they are homogeneous. Structures and classes are designed to handle heterogeneous data.

 

Question 4. Structure is declared using the keyword …………………
(a) Structure
(b) struct
(c) Stru
(d) STRUCT
Answer: (b) struct
In simple words: In programming, to tell the computer you want to make a new structure, you must use the special word "struct".

🎯 Exam Tip: Keywords in programming languages are case-sensitive. Always use the correct lowercase 'struct' for declarations.

 

Question 5. Identify the structure name from the following; struct Student balu;
(a) balu
(b) struct
(c) Student
(d) None of these
Answer: (c) Student
In simple words: In the example, 'Student' is the name given to the blueprint for your structure, telling what kind of information it will hold. 'Balu' is a specific item made from that blueprint.

🎯 Exam Tip: Distinguish between the structure *tag* (blueprint name) and the structure *variable* (instance of the blueprint).

 

Question 6. Identify the structure variable (object) from the following: struct Student balu;
(a) balu
(b) struct
(c) Student
(d) None of these
Answer: (a) balu
In simple words: In the example, 'balu' is a real item created using the 'Student' structure design. It's like having a blueprint for a house called 'Student', and 'balu' is one specific house built from it.

🎯 Exam Tip: A structure variable (or object) is an instance of the structure type and holds the actual data according to the structure's definition.

 

Question 7. How much of memory is required for the object of the following structure in Dev C++.
struct Student
{
long rollno;
int age;
float weight;
}balu, frank;
(a) 12 Bytes
(b) 8 Bytes
(c) 10 Bytes
(d) None of these
Answer: (a) 12 Bytes
In simple words: In Dev C++, a 'long' number takes 4 bytes, an 'int' takes 4 bytes, and a 'float' takes 4 bytes. Adding these up (4+4+4) gives a total of 12 bytes for each student's data.

🎯 Exam Tip: Memory allocation for data types can vary between compilers and operating systems. For Dev C++, long, int, and float often take 4 bytes each.

 

Question 8. How much of memory is required for the object of the following structure in Turbo C++.
struct Student
{
long rollno;
int age;
float weight;
}balu, frank;
(a) 12 Bytes
(b) 8 Bytes
(c) 10 Bytes
(d) None of these
Answer: (c) 10 Bytes
In simple words: In Turbo C++, a 'long' number takes 4 bytes, an 'int' takes 2 bytes, and a 'float' takes 4 bytes. Adding these up (4+2+4) gives a total of 10 bytes for each student's data.

🎯 Exam Tip: Always be aware that memory sizes for data types (especially `int` and `long`) can differ based on the compiler and system architecture (e.g., 16-bit vs. 32-bit vs. 64-bit environments).

 

Question 9. If the members are pointer types then ……………….. is used to access the structure members.
(a) \( \rightarrow \)
(b) \( \leftarrow \)
(c) .(dot)
(d) None of these
Answer: (a) \( \rightarrow \)
In simple words: When you have a pointer that points to a structure, you use the arrow symbol to reach the individual items inside that structure. This is different from using a dot if you have the structure itself.

🎯 Exam Tip: Remember the rule: use the dot operator (`.`) for direct structure variables and the arrow operator (`->`) for structure pointers to access members.

 

Question 10. A structure without a …………….. is called an anonymous structure.
(a) Name
(b) Tag
(c) Name/Tag
(d) None of these
Answer: (c) Name/Tag
In simple words: If you create a structure but don't give it a specific name or tag, it's called an anonymous structure. It means you can't use that name later to create more of the same type of structure.

🎯 Exam Tip: Anonymous structures are useful for one-off definitions, often when declaring a variable of that structure type immediately after its definition.

 

Question 11. ………………….. operator is used to accessing structure member.
(a) ::
(b) @
(c) .(dot)
(d) $
Answer: (c) .(dot)
In simple words: To get to an item inside a structure, you put a dot between the structure's name and the item's name. This connects them so you can use that specific item.

🎯 Exam Tip: The dot operator is fundamental for accessing members of a structure variable, distinguishing it from pointers that use the arrow operator.

 

Question 12. The structure declared within another structure is called a …………….. structure.
(a) Nested
(b) Group
(c) Block
(d) None of these
Answer: (a) Nested
In simple words: When you put one structure inside another structure, like a box inside a bigger box, it's called a nested structure. This helps organize complex data.

🎯 Exam Tip: Nested structures are very common for organizing related data, such as a `Date` structure (day, month, year) inside a `Person` structure.

 

Question 13. ……………. structures act as members of another structure.
(a) Nested
(b) Group
(c) Block
(d) None of these
Answer: (a) Nested
In simple words: Structures that are placed inside other structures work like any other item belonging to the outer structure. This helps to group related information together in a clear way.

🎯 Exam Tip: This question emphasizes the role of a nested structure as a component (member) within a larger, enclosing structure.

 

Question 14. The members of the child structure can be accessed as …………………….
(a) Child structure name. Parent structure name. Member name
(a) Parent structure name. Child structure name. Member name
(a) Parent structure name. Member name. Child structure name
(a) Member name. Parent structure name. Child structure name
Answer: (a) Parent structure name. Child structure name. Member name
In simple words: To reach an item in a small structure that is inside a bigger structure, you first say the big structure's name, then the small structure's name, and finally the item's name, all separated by dots. It's like giving a full address.

🎯 Exam Tip: Accessing members in nested structures requires a chain of dot operators, starting from the outermost structure variable and working inwards.

 

Question 15. A structure variable can be passed to a function in a similar way of passing any argument that is of ……………………. data type.
(a) Derived
(b) User-defined
(c) Built-in
(d) None of these
Answer: (c) Built-in
In simple words: You can send a structure to a function just like you send simple types of data, such as whole numbers or single characters. Structures act like regular data types when used in function calls.

🎯 Exam Tip: Passing structures to functions can be done by value or by reference, similar to how basic data types are handled.

 

Question 16. If the structure itself is an argument to a function, then it is called ………………..
(a) Call by value
(b) Call by Reference
(c) Call by Expression
(d) None of these
Answer: (a) Call by value
In simple words: When you send a whole structure to a function, and the function works on a copy of that structure, it's called "call by value." Any changes made inside the function won't affect the original structure.

🎯 Exam Tip: In call by value, a copy of the structure is made, which consumes more memory and time, especially for large structures.

 

Question 17. If the reference of the structure is passed as an argument then it is called ……………….
(a) Call by value
(b) Call by Reference
(c) Call by Expression
(d) None of these
Answer: (b) Call by Reference
In simple words: If you send only the memory address (a reference) of a structure to a function, any changes the function makes to the structure will change the original structure. This method is called "call by reference."

🎯 Exam Tip: Call by reference is generally preferred for large structures because it avoids creating a copy, saving memory and improving performance.

 

Question 18. When a structure is passed as an argument to a function using ……………… method, any change made to the contents of the structure variable inside the function to which it is passed do not affect the structure variable used as an argument.
(a) Call by value
(b) Call by Reference
(c) Call by Expression
(d) None of these
Answer: (a) Call by value
In simple words: If you send a structure by "call by value," the function gets a separate copy. So, if the function changes anything in that copy, the original structure outside the function remains untouched.

🎯 Exam Tip: Understand that call by value protects the original data from modification within the function, which can be useful when you need to preserve the source state.

 

Question 19. In ……………….method of passing the structures to functions, any change made to the contents of structure variable inside the function are reflected back to the calling function.
(a) Call by value
(b) Call by Reference
(c) Call by Expression
(d) None of these
Answer: (b) Call by Reference
In simple words: When a structure is passed by "call by reference," the function directly works with the original structure using its memory address. This means any changes made by the function will directly update the original structure's values.

🎯 Exam Tip: Use call by reference when you intend for the function to modify the original structure's data.

 

Question 20. Structures are usually passed by reference method because ……………..
(a) It saves the memory space
(b) Executes faster
(c) Both A and B
(d) None of these
Answer: (c) Both A and B
In simple words: Passing structures by reference is better because it avoids making a new copy of the entire structure. This saves computer memory and also makes the program run quicker.

🎯 Exam Tip: For performance and memory efficiency, especially with large structures, call by reference is the optimal method for passing structures to functions.

 

Question 21. Identify the correct statement from the following.
(a) A structured object can also be assigned to another structure object only if both the objects are of the same structure type.
(b) The structure elements can be initialized either by using separate assignment statements or at the time of declaration by surrounding its values with braces.
(c) Array of structure variable can also be created.
(d) All the above
Answer: (d) All the above
In simple words: All the statements listed are true. You can copy one structure to another if they are the same type, set up values for structure items when you create them, and also make lists (arrays) of structures.

🎯 Exam Tip: This question tests your comprehensive understanding of structure features, including assignment, initialization, and array creation.

Very Short Answers (2 Marks)

 

Question 1. What is the drawback of an array?
Answer: An array has a significant drawback because it can only store data items of the same type. If a situation requires representing objects with different data types, an array cannot support them. Additionally, if multiple variables are used but not stored in continuous memory locations, this can increase the time taken for searching operations.
In simple words: Arrays can only hold data of the same type. If you need to store different types of information together, an array cannot do that. Also, if data is scattered in memory, finding things in arrays can take longer.

🎯 Exam Tip: Focus on homogeneity and static memory allocation as primary drawbacks of arrays; they are fixed in size and cannot mix data types.

 

Question 2. What is the advantage of structure?
Answer: The main advantage of a structure is that it provides a way to store different types of data as part of a single, logical unit. All these diverse data items are placed in one continuous block of memory. This organization makes it easier to manage and refer to related information.
In simple words: Structures are good because they let you keep different kinds of information, like a name and a number, together in one place. They store all this related data in a continuous block in the computer's memory, making it tidy and easy to use.

🎯 Exam Tip: Highlight the ability to group *heterogeneous* data types into a *single logical unit* and *contiguous memory allocation* as key advantages of structures.

 

Question 3. What are global objects?
Answer: Global objects are created when they are declared along with the definition of a structure. This means they are accessible from any part of the program, not just within a specific function or block. Their values can be used or changed by any function in the entire program.
In simple words: Global objects are special items that are made at the same time a structure is defined. They can be seen and used by any part of the program, everywhere.

🎯 Exam Tip: Define global objects as those declared outside any function, making them accessible throughout the entire program's scope.

 

Question 4. Write note on the anonymous structure.
Answer: An anonymous structure is a structure that is declared without a specific name or tag. Instead, a variable (or object) of this structure type is declared directly when the structure itself is defined. This type of structure is useful when you only need to create a single instance and don't plan to define other variables of the same structure type later in the program. For example:

struct
{
  long rollno;
  int age;
  float weight;
} student;
The variable `student` can then be used to access its elements, such as `student.rollno`, `student.age`, and `student.weight`.
In simple words: An anonymous structure is a structure without a name. You declare it and create its variable all at once. This is handy when you only need one item of that specific structure type.

🎯 Exam Tip: The key feature of an anonymous structure is the absence of a `tag-name`, requiring immediate declaration of its variable(s) upon definition.

 

Question 5. Define Nested structure.
Answer: A nested structure refers to a structure that is declared as a member inside another structure. This allows for more complex data organization, where one component of a larger data record is itself a structured collection of data. It helps in logically grouping related data together within a parent structure.
In simple words: A nested structure is simply one structure placed inside another structure. It's like having a small box of things (a structure) placed inside a bigger box of other things (another structure) to keep everything organized.

🎯 Exam Tip: Recognize that nested structures are essential for representing hierarchical or composite data types in programming, enhancing modularity and clarity.

 

Question 6. Give an example of nested structure.
Answer: Here is an example of a nested structure. It shows how one structure, `dob` (date of birth), can be included as a member within another structure, `Student`, to keep related data logically grouped:

struct Student
{
  int age;
  float height, weight;
  struct dob
  {
    int date;
    char month[4];
    int year;
  };
} mahesh;
In this example, `dob` is the inner (nested) structure, and `Student` is the outer structure. This allows a `Student` object to include date-related information in an organized way.
In simple words: Imagine a student's record. You might have their age, height, and weight. But for their birthday, you might want to store the day, month, and year all together. So, you make a small structure for the birthday and put it inside the bigger student structure.

🎯 Exam Tip: When providing examples, always clearly show both the outer and inner structure definitions, demonstrating how the inner structure is declared *within* the outer one.

 

Question 7. How to access nested member structure?
Answer: Nested structures act as members of another structure. To access the members of the child structure, you need to use a sequence of dot operators. You start with the parent structure's variable name, then use a dot to access the child structure's variable name (which is a member of the parent), and finally, use another dot to access the desired member of the child structure. This creates a clear path to the specific data element.
For example, using the previous `Student` and `dob` structures, if `mahesh` is a variable of type `Student`, you would access the `date` member of `dob` as:
`mahesh.dob.date`
In simple words: To get to an item inside a small structure that lives inside a bigger structure, you use dots. First, the big structure's name, then the small structure's name, then the item's name. It's like giving a full address for the item.

🎯 Exam Tip: Emphasize the chain of dot operators (`.`) for accessing nested members, starting from the outermost structure variable.

Short Answers 3 Marks

 

Question 1. Write the syntax of defining a structure? Give an example.
Answer: A structure is defined using the keyword `struct`. This keyword tells the compiler that a new user-defined data type is being created. The syntax allows for organizing different data types under a single name. The definition provides a blueprint for what the structure will contain.
Syntax:

struct structure_name
{
  type member-name1;
  type member-name2;
  // ... more members
} reference_name; // Optional: can declare objects directly here

An optional `reference_name` can be used directly to declare objects (variables) of the structure type immediately after its definition.
Example:
struct Student
{
  long rollno;
  int age;
  float weight;
}; // Semicolon is crucial here

This example defines a `Student` structure that contains a roll number, age, and weight. We can then create variables (objects) of type `Student` later in the program.
In simple words: To define a structure, you start with the word `struct`, then give it a name, and then list all the different pieces of information (members) it will hold inside curly brackets. Don't forget the semicolon at the end of the curly bracket. For instance, a `Student` structure could hold their roll number, age, and weight.

🎯 Exam Tip: Always include the semicolon after the closing curly brace of a structure definition; it's a common oversight.

 

Question 2. How memory is allocated for a structure?
Answer: Memory allocation for a structure is determined by the size of its individual members. When a structure is declared, like the `Student` example below, the total memory required for a variable of that structure type is the sum of the memory sizes of all its members. These members (also called fields) are stored in contiguous memory locations. The compiler calculates this total size, potentially adding padding bytes for alignment purposes, to ensure efficient access. This means each instance of the structure will occupy a specific, calculated amount of memory.
Consider the following structure:

struct Student
{
  long rollno;
  int age;
  float weight;
};

In this structure, if `long` takes 4 bytes, `int` takes 4 bytes, and `float` takes 4 bytes (e.g., in Dev C++), then a `Student` variable would occupy `4 + 4 + 4 = 12` bytes. The memory for these variables is reserved at compile time.
In simple words: The computer gives memory to a structure by adding up how much space each item inside it needs. For example, if a student structure has a roll number, age, and weight, the computer adds the memory for each to get the total memory for one student. This memory is given all in one continuous block.

🎯 Exam Tip: Explain that memory for a structure is the sum of its members' sizes, often with padding for alignment, and it's allocated contiguously to keep related data together.

 

Question 1. Explain structure assignments in detail.
Answer:
When you work with structures, you can copy all the data from one structure variable to another at once, instead of copying each part separately. This is a very efficient way to handle complex data types.
For example, imagine we have two students, Mahesh and Praveen. If they have the same age, height, and weight, we can easily copy Mahesh's details to Praveen's record. First, we define a structure for a student and create a variable for Mahesh:

struct Student
{
int age;
float height, weight;
} mahesh;

Mahesh's age is 17, his height is 164.5, and his weight is 52.5. We can assign these values and then copy them to Praveen's variable like this:
mahesh = {17, 164.5, 52.5};
praveen = mahesh;

This line will then copy all of Mahesh's details (age, height, weight) into Praveen's record. This method greatly simplifies data transfer between structure variables of the same type.
In simple words: You can copy all the information from one student's record (a structure variable) to another student's record directly. You don't have to copy each item like age, height, and weight one by one.

🎯 Exam Tip: Remember that direct structure assignment (`struct1 = struct2;`) only works if both structures are of the exact same type; otherwise, you'll need to copy members individually.

TN Board Solutions Class 11 Computer Science Chapter 12 Arrays and Structures

Students can now access the TN Board Solutions for Chapter 12 Arrays and Structures prepared by teachers on our website. These solutions cover all questions in exercise in your Class 11 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.

Detailed Explanations for Chapter 12 Arrays and Structures

Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 11 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 11 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.

Benefits of using Computer Science Class 11 Solved Papers

Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 11 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 12 Arrays and Structures to get a complete preparation experience.

FAQs

Where can I find the latest Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures for the 2026-27 session?

The complete and updated Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures is available for free on StudiesToday.com. These solutions for Class 11 Computer Science are as per latest TN Board curriculum.

Are the Computer Science TN Board solutions for Class 11 updated for the new 50% competency-based exam pattern?

Yes, our experts have revised the Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.

How do these Class 11 TN Board solutions help in scoring 90% plus marks?

Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures will help students to get full marks in the theory paper.

Do you offer Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures in multiple languages like Hindi and English?

Yes, we provide bilingual support for Class 11 Computer Science. You can access Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures in both English and Hindi medium.

Is it possible to download the Computer Science TN Board solutions for Class 11 as a PDF?

Yes, you can download the entire Samacheer Kalvi Class 11 Computer Science Solutions Chapter 12 Arrays and Structures in printable PDF format for offline study on any device.