Help ASAP Will rate Match the cout with its corresponding ou

Help ASAP Will rate!

Match the cout with its corresponding output based on the following assumptions.

Addresses in memory:

Variable declaration and initiation:

  

int val[3]= {1,2,3};

int *ptrVal;

ptrVal = &val[0];

cout << val;

cout << ptrVal;

cout << &val[2];

cout << *ptrVal++;

cout << ++*ptrVal;

what is the cout value from the options listed below?

A.

X1001

B.

1

C.

X1001

D.

3

E.

X1003

X1001 X1002 X1003

Solution

Hi,
I think the options are not clear so I am writing the answer of all the cout written in the program.Hope,it would be much better in knowledge point of view and you can also decide the option.

Answer :
1) cout << val ; This will print \"X1001 \" as we only gave variable name but not the position due to which address of first value in array been sent

2)cout <<ptrVal ; This will print \"X1001 \" as here the value of ptrVal pointer is been sent and the pointer contains the value of the first value of the array

3)cout << &val[2] ; This will print \"X1003 \" as here the address of the last variable of array is sent therefore address of last variable is printed

4)cout << *ptrVal++; This will print \"1\" and then the value is incremented by 1 in memory.Therefore,now val[0] = 2 or *ptrVal = 2 (both are refering to same memory place ).

5)coubt << ++ * ptrVal; This will first increment the value of variable pointed by ptrVal by 1 and then it will print the value i.e \"3\".

Therefore,the output will be

X1001

X1001

X1003

1

3

Hope,the answer helped you and If you require any other help or any other query related to this question.Please feel free to contact us , we will love to help you

Help ASAP Will rate! Match the cout with its corresponding output based on the following assumptions. Addresses in memory: Variable declaration and initiation:
Help ASAP Will rate! Match the cout with its corresponding output based on the following assumptions. Addresses in memory: Variable declaration and initiation:

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site