Mark the following statements as true or false.
A double type is an example of a simple data type. (1)
A one-dimensional array is an example of a structured data type. (1)
The size of an array is determined at compile time. (1,6)
Given the declaration:
int list[10];
the statement:
list[5] - list[3] * list[2];
updates the content of the fifth component of the array list. (2)
If an array index goes out of bounds, the
program always terminates in an error. (3)The only aggregate operations allowable on int arrays are the increment and decrement operations. (5)
Arrays can be passed as parameters to a function either by value or by reference. (6)
A function can return a value of type array. (6)
In C++, some aggregate operations are allowed for strings. (11,12,13)
The declaration:
char name [16] = "John K. Miller";
declares name to be an array of 15 characters because the string "John K. Miller" has only 14 characters. (11)
The declaration:
char str = "Sunny Day";
declares str to be a string of an unspecified length. (11)
As parameters, two-dimensional arrays are passed either by value or by reference. (15,16)
a.
A double type is a simple data type. Hence, the given statement is “True”.
A data type is called simple if variables of that type can store only one valueat a time. In contrast, in a structured data type, each data item is a collection of otherdata items. Simple data types are building blocks of structured data types.
A double type is a simple data type. Hence, the given statement is “True”.
Explanation of Solution
Since a double type can store a single value at a time it is a simple data type.
b.
One-dimensional array is an example of a structured data type. Hence, the given statement is “True”.
A data type is called simple if variables of that type can store only one valueat a time. In contrast, in a structured data type, each data item is a collection of otherdata items. Simple data types are building blocks of structured data types.
One-dimensional array is an example of a structured data type. Hence, the given statement is “True”.
Explanation of Solution
One-dimensional array is an example of a structured data type, as it can store a collection of other data items.
c.
The size of an array is determined at compile time. Hence, the given statement is “True”.
An array is a collection of a fixed number of components (also called elements)all of the same data type and in contiguous (that is, adjacent) memory space.
The size of an array is determined at compile time. Hence, the given statement is “True”.
Explanation of Solution
An array is a collection of a fixed number of components hence the size of an array is determined at compile time.
d.
The statement does not update the fifth component. Hence, the given statement is “False”.
In C++[ ] is an operator called the array subscripting operator and the array index starts at 0.
The statement does not update the fifth component. Hence, the given statement is “False”.
Explanation of Solution
The statement updates the sixth component of the array list as the subscript begins with 0.
e.
If an array index goes out of bounds, the program does not necessarily terminatein an error. Hence, the given statement is “False”.
C++ does not check whether the index value is within range. If the index goes out of bounds and the program tries toaccess the component specified by the index, then whatever memory location is indicatedby the index that location is accessed. This can result in altering or accessingthe data of a memory location that was never intended to be modified or accessed. It can also lead to accessing a protected memory that causes the program to instantly halt. Hence, several unknown things can happen if the index goes out of bounds during execution.
If an array index goes out of bounds, the program does not necessarily terminatein an error. Hence, the given statement is “False”.
Explanation of Solution
If the index goes out of bounds and the program tries to access the component specified by the index, then whatever memory location is indicated by the index that location is accessed. This may or may not cause the program to instantly halt or terminate in an error.
f.
C++ does not allow aggregateoperations on an array. Hence, the given statement is “False”.
An aggregate operation on an array is any operation thatmanipulates the entire array as a single unit.
C++ does not allow aggregateoperations on an array. Hence, the given statement is “False”.
Explanation of Solution
C++ does not allow aggregate operations on an array.
g.
Arrays can be passed as parameters to a function never by value but only by reference. Hence, the given statement is “False”.
In C++, arrays are passed by reference only. Because arrays are passed by reference only, the &symbol is never used when declaringan array as a formal parameter.
Arrays can be passed as parameters to a function never by value but only by reference. Hence, the given statement is “False”.
Explanation of Solution
In C++, arrays are passed by reference only and never by value.
h.
A function cannot return a value of type array. Hence, the given statement is “False”.
A function cannot return a value of type array.
A function cannot return a value of type array. Hence, the given statement is “False”.
Explanation of Solution
A function cannot return a value of type array.
i.
In C++, some aggregate operations are allowed for strings. Hence, the given statement is “True”.
Most rules that apply to arrays apply to C-strings as well. Aggregateoperations, such as assignment and comparison, are not allowed on arrays. Also the input/output of arrays is done component-wise. But, C++ allows aggregate operations of the input and output on C-strings which are nothing but character arrays terminated with the null character.
In C++, some aggregate operations are allowed for strings. Hence, the given statement is “True”.
Explanation of Solution
C++ allows aggregate operations of the input and output on C-strings which are nothing but character arrays.
j.
The name array is of size 16 and not 15. Hence, the given statement is “False”.
The name array is of size 16 which is mentioned in the declaration of the variable and not the size of string stored into it. There remains 1 unused component in the name array.
The name array is of size 16 and not 15. Hence, the given statement is “False”.
Explanation of Solution
The name array is of size 16 which is mentioned in the declaration of the variable and not the size of string stored into it. There remains 1 unused component in the name array.
k.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. Hence, the given statement is “False”.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. For assignment operation on c-strings (char arrays) c-string functions are needed.
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. Hence, the given statement is “False”.
Explanation of Solution
Aggregate operation such as assignment is not allowed on arrays and the statement is illegal. For assignment operation on c-strings (char arrays) c-string functions are needed.
l.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference only. Hence, the given statement is “False”.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference.
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference only. Hence, the given statement is “False”.
Explanation of Solution
Two-dimensional arrays can be passed as parameters to a function, and they arepassed by reference.
Want to see more full solutions like this?
Chapter 8 Solutions
C++ Programming: From Problem Analysis to Program Design
- Make a template function that returns the average of all the elements of an array. The arguments to the function should be the array name and the size of the array (type int). In main(), exercise the function with arrays of type int, long, double, and char. Note: explain by double line comments solve as soon as possible use c++ languagearrow_forwardWrite a template function that returns the average of all the elements of an array. The arguments to the function should be the array name and the size of the array (type int). In main(), exercise the function with arrays of type int, long, double, and char. Note: use OOP and C++arrow_forwardImplement a C program that reorders the elements of an array of integers such that the new order is in ascending order (i.e. the first number is the smallest). You must have a main function and a swap function. The function int main() will declare an array with the values {-13,-51,-78,-91,-42,0}. This array will be passed to the swap function. The function void swap() will perform the necessary operations to reorder the elements of the array. Note that because swap is a void function, we cannot return the array back to the main function, meaning we must manipulate memory instead! After swap() is finished, have main() print the original array to show the new element order. Do not hard code your solution. If we test your code with different array values, we should still get the correct output.arrow_forward
- Write a function for given main functionint * return_an_array(int n)which takes an integer n and returns a pointer to an array (allocated off of the heap inthe function) containing the digits of n in the appropriate positions. If n = 0 return 0(which is the “null” pointer). Recall an array name is just a pointer to the first element ofthe array. Please use following main to test your function.int main() {int *a = return_an_array(23542); // array of size 5for(int i=0;i<5;i++)cout<<a[i]<<" "; // print 2 3 5 4 2cout<<endl;delete [] a;int *b = return_an_array(12345678); // array of size 8for(int i=0;i<8;i++)cout<<b[i]<<" "; // print 1 2 3 4 5 6 7 8cout<<endl;delete [] b;return 0;}arrow_forwardWrite a code in C++ for inserting the following numbers in the array. (1) Create a Dynamic Array of size 14 using new operator.(2) Insert all numbers in the Array.(3) Print all elements of the Array. 4, 95, 23, 52, 65, 753, 878, 78, 95, 283, 197, 56, 79, 9arrow_forwardCan you explain the memory allocation of a dynamic array?arrow_forward
- 4. Write a program in C or Java to find the maximum and minimum element in an array.Test Data :Input the number of elements to be stored in the array : 3Input 3 elements in the array :element - 0 : 45element - 1 : 25element - 2 : 21Expected Output :Maximum element is : 45Minimum element is : 21arrow_forwardIn C++, how can one easily duplicate a set of shared pointers into another array? Make a list of various solutions to the situation you've been given. Is it true that copying shared pointers also copies the objects they manage? Explainarrow_forwardAn array with any number of elements is said to be repeating if any two or more of the elements are appearing in sequential an indexes after each other.Write a C++ function that accepts an integer array and returns 1 or “Repeating” if it is a repeating array, otherwise it returns 0 or “Not Repeating”. For Instance:2, 3, 5, 6, 7, 7, 7, 6, 8, 10 - Repeating2, 3, 4, 6, 4, 6, 4, 7, 8, 9 - Not repeatingarrow_forward
- Write three functions for: mean, remove, display //include any standard libraries needed // - passes in an array along with the size of the array // - returns the mean of all values stored in the array double mean( const double array [ ], int arraySize); // - Passes in an array, the size of the array by reference, and the index of a value to be removed from the array. // - Removes the value at this index by shifting all of the values after this value up, keeping the same relative order of all values not removed. // - Refuces arraySize by 1. void remove (double array[], not &arraySize, int index); // - Passes in an array and the size of the array. // - outputs each value in the array separated by a comma and space, with mo comma, space or beeline at the end. void display (const double array[], int arraySize); const int ARR_CAP = 100; int main (int argc, char *argv[]){// verify file name provided on command line // open file and verify it opened // declare an array of doubles of…arrow_forward2. Write a program which sorts the CGPA array having cgpa of all students in ascending order by using bubble sort and make use of pointers for each and every variable and constant and array.arrow_forward3. Consider an 1-d array of type int and a pointer pointing variable pointing to the 2nd item of the array. Write down the code for the following: int arr(10) = (5,6,23,4,89,70,12,78,33); int *ptr = arr+1; (a) Print the first item of the array using ptr. (b) Print all prime numbers of the array using value at address. (c) Print the last item of the array using a pointer to an array. You are not allowed to initialize the pointer to the address of the last item. Iterate using a loop to change the value of the pointer. (d) Now print the array in reverse order using a pointer. 101arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning