Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ questions 1)what is the output? int xyz [ ] = {2,4,6,8}; for (int a = 0; a {

ID: 3553605 • Letter: C

Question

c++ questions

1)what is the output?

int xyz [ ] = {2,4,6,8};

for (int a = 0; a

{

*( xyz +a) = xyz [a] +3;

}


cout<<xyz[2];


2)When an array is passed to a function, is the entire array passed so that a temporary copy is created in memory? Explain.


3Define the role of the following terms with regard to dynamic memory:


new:


delete:


heap:


stack:


4)Write a loop that will display the numbers 10, 15 and 20 only


6) Does this work when comparing arrays? Why or why not?

If (ara==arb)

cout<<"match";


7)Given the declaration of my_array initialized to 5 10 15 20 25,

use the following code to answer the questions.


Int count;

Const int SIZE = 5;

for (count = 0; count < SIZE; count++)

cout << *(my_array + count)<< " ";


What value is output during the third iteration?


What value is output during the second iteration?

Explanation / Answer

1.)

output is 9(old xyz[2] + 3)


2.)

When an array is passed to a function, the pointer to the first element is passed and it's size. So, no a copy of the array is not created in the memory.


4.)

for(int i=10;i<=20;i=i+5){cout<<i<<endl;}


6.)

No, comparing arrays like this will not work.

ara and arb contain the pointers/addresses to the first elements of the two arrays, and not the values of the elements in the arrays.


7.)

Int count;

Const int SIZE = 5;

for (count = 0; count < SIZE; count++)

cout << *(my_array + count)<< " ";


In the 3rd iteration, count = 2, *(my_array+count) will be the 3rd element of my_array

So 15 is printed in the 3rd iteration


In the 2nd iteration, count = 1, *(my_array+count) will be the 2nd element of my_array

So 10 is printed in the 2nd iteration

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote