Assume the existence of a class Arr with two (public) data members: a pointer to integer named arr_ptr, and an integer variable named length that will contain the number of elements in the array. Assume the variable a has been declared to be of type Arr, an array has been allocated and assigned to arr_ptr, and length has been assigned the proper value (i.e., the number of elements in the array). Write the code to add 1 to each element of the array.
.
.
Click on the title for the solution
.
.
for (int i = 0; i < a.length; i++)
{
a.arr_ptr[i] += 1;
}
.
Click on the title for the solution
.
.
This is the answer:
:
for (int i = 0; i < a.length; i++)
{
a.arr_ptr[i] += 1;
}
Comments
Post a Comment