Question

the coding language is in c++ An array named testScores has already been declared. -size= 5...

the coding language is in c++

An array named testScores has already been declared.

-size= 5
-data type = float
- the array has already been initialized these values: 77, 88.5, 90, 93, 71.5
-Write one statement to declare a pointer named: ptr
- in the same statement, assign the address to the testScores array to the pointer
-write one statement to output the memory address of the array element at testScores[0]
-Write a for loop to output the values in the testScores array declared above.
-assume the pointer holds the address of the first bite of the array
-use the pointer in the cout statement. In other words, dereference the pointer
- Include pointer arithmetic to move the pointer from one array element to the next

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have implemented the above steps in c++. I have added comments for each line in code for you to understand it.

Note: You may see the screenshot of code to have better understanding of the indentation.

C++ Code:

#include <iostream>
using namespace std;

//main function
int main()
{
    //initialize the float array
    float testScores[5] = {77, 88.5, 90, 93, 71.5};
  
    //assign a pointer to the array
    float *ptr = testScores;
  
    //output memory address of first element in array
    cout<<"Memory address of first element using & operator: "<<&testScores[0]<<endl;
    cout<<"Memory address of first element using pointer: "<<ptr<<endl;
  
    //display array elements using pointer in for loop
    cout<<"Array elements using pointer: \n";
    for(int i=0;i<5;i++)
    {
        //dereference pointer using *ptr and
        //add i for subsequent elements in array
        cout<<*(ptr+i)<<endl;
    }

    return 0;
}


Output:

Memory address of first element using & operator: 0x7fff98c6ecbo Memory address of first element using pointer: 0x7fff98c6ecb

Screenshot of code:

#include <iostream> 2 using namespace std; 4 //main function 5 int main() 6- { //initialize the float array float testScores[

Add a comment
Know the answer?
Add Answer to:
the coding language is in c++ An array named testScores has already been declared. -size= 5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C An array ints of integers has already been declared and initialized. A function printint...

    In C An array ints of integers has already been declared and initialized. A function printint has been defined with the following prototype: void printint(int *); Write code that will call printint with a pointer to the second value in the array ints. Note: you will not need to declare an int variable.

  • assume that input is an int array. the array is already declared and initialized wnd every...

    assume that input is an int array. the array is already declared and initialized wnd every element is assigned to an integer number. in addition assume that the array contains at least 1 element. write a code that contains one while loop abd no other loops to find both maximum and minimum numbers from input. then outout the maximum minus the minumum to the console window. (using java eclipse coding)

  • C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array...

    C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...

  • Using Structures in C language programming

    Write code to accomplish each of the following:Define a structure called Dove containing int variable dovNo and char array dovArr with values that may be as long as 25 characters (including the terminating null character).Define dove to be a synonym for the type struct Dove.Use Dove to declare variable a to be of type struct Dove, array b[ 10 ] to be of type struct Dove and variable ptr to be of type pointer to struct Dove.Read a dovNo and a dovArr from the keyboard into the individual members of variable a.Assign the member values of variable a to element 3 of array b.Assign the address...

  • a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a...

    a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...

  • Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index...

    Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array? Shows the code. Consider the declaration: int v[1]; What is the index of the last element of this array? Declare an array named a of 10 int elements and initialize the elements (starting with the first) to the...

  • using visual studio 2) For each of the following, write C++ statements that perform the specified...

    using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...

  • TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes...

    TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes P1 to point to the memory location 1001. ANSWER: T 2. When you return a dynamic array to the freestore, you must include the number of elements in the array 3. You can assign an array to a pointer variable. 4. The size of dynamic arrays must be declared at compile time. 5. int *pl; declares a static variable. ANSWER: F ANSWER: F ANSWER:...

  • Assuming that the array upc declared below has already been filled with MAX_LENGTH values, write a...

    Assuming that the array upc declared below has already been filled with MAX_LENGTH values, write a function that will ask to input an integer from the keyboard and perform a sequential search of the array for the input integer. If the input integer is found, print the index of the matching value in the array. Otherwise, print "Not found". Include declarations for all variables that you use.             const int MAX_LENGTH = 25;             int upc[MAX_LENGTH]; Please write in C++

  • Assume that integer array b[5] and integer pointer variable bPtr have been defined. Write a statement...

    Assume that integer array b[5] and integer pointer variable bPtr have been defined. Write a statement to set bPtr equal to the address of the first element in array b. Write a statement using pointer expression to reference the array element b[3]. please make sure answer should be detailed ,  correct and in C language.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT