Print Friendly and PDF
(Write C++ Statements) For each of the following, write a single statement that performs the specified task. Assume that long variables value1 and value2 have been declared and value1 has been initialized to 200000.
(Write C++ Statements) For each of the following, write a single statement that performs the specified task. Assume that long variables value1 and value2 have been declared and value1 has been initialized to 200000.

a) Declare the variable longPtr to be a pointer to an object of type long.

b) Assign the address of variable value1 to pointer variable longPtr.

c) Print the value of the object pointed to by longPtr.

d) Assign the value of the object pointed to by longPtr to variable value2.

e) Print the value of value2.

f) Print the address of value1.

g) Print the address stored in longPtr. Is the value printed the same as value1’s address?

Solution:


a)
 
long *longPtr;
 
b)
 
longPtr = &value1;
 
c)
 
cout << *longPtr;
 
d)
 
value2 = *longPtr;
 
e)
 
cout << value2;
 
f)
 
cout << &value1;
 
g)
 
cout << longPtr;
YES
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: