Show what the cout statement would be if it used pointer not

Show what the cout statement would be if it used pointer notation instead

void main()

{

const int size=5;

int numbers[SIZE]={1,2,3,4,5};

int count;

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

{

cout<<numbers[count]<<endl;

}

}

Solution

Answer:

I believe it is :

cout<<*numbers + count*4 <<endl;

Numbers is an array. So it does not hold the value. It only stores the address where the value is stored.

But *number will go to that address and will read the value. And every integer is 4 bytes ,

so, to get the next value of the array, you have to go to the address and more four bytes to get the next value. And move four bytes again to get the 3rd value.So I have +4*count.

Show what the cout statement would be if it used pointer notation instead void main() { const int size=5; int numbers[SIZE]={1,2,3,4,5}; int count; for(count=0;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site