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

Review: Introduction store ? 1 What does a pointer variable declaze a variable o

ID: 3602857 • Letter: R

Question



Review: Introduction store ? 1 What does a pointer variable declaze a variable of type double Write the statements required to with a value of 2.71828, the address of a double, aasign to the pointer variable, and print variable thru the use oft the pointer declare a pointer variable that can hold oss of the double variable le the addr out the value of the doub 3.What are the two legal operations that (stack memory b. When is dynamia memory memory applied to pointer ry) allocated/deallocated ? (heap memory) allocated/deallocated ? variables ? a When is atatio memory ( 5. The name of the dynamic memory management operator for: a. dynamic memory allocation. b. dynamic memory deallocation. 6· what does the dynamic memory allocation operator return if insufficient memory is available for the request ? 7. Write the statements required to: declare a pointer variable that can hold the address of a dou hold a double and assign the address of this area to the pointer variable, stoze the value: 3.14159 in the allocated memory area, ble, dynamically allocate memory to print out the stored value, deallocate the memory. 8. write the statements required to: declare a variable of type float with a value of 3.14159, a pointer variable that can hold the address of a float, assign the address of the float variable to the pointer variable, and print out the value of the float variable thru the use of the pointer variable. 9. Given the declarations: cypedef int PT_INT int PT INT x, y z a, b, c; Determine which of the following are VALID (are legal AND would produce a meaningful result or INVALID code segments. Do NOT assume that any pointers already hold an address. Consider earh as an INDEPENDENT problem

Explanation / Answer

Answer 9

a,b,c are int variables and x,y,z are pointers which will store the address of int variables

a. Valid

z stores the address of a and x points to the same address as z. So b + *x results in 30

b. Valid

x is allocated memory dynamically and then assigned the value 20.

c. Invalid.

x is a pointer being assigned to a int variable which will result in SegFault.

d. Invalid

Since z doesn't hold any address, assigning z to y will throw an exception

e. Valid

This will allocate memory to x, and then assign the address stored in x to z as well. So x & z will point to same memory locations

f. Valid

This will allocate a new memory dynamically to x, then assign c = 10. Then the address pointed by x will contain value 50.

g. Valid

A memory is allocated to x and then, cout will display value stored at address x which is 8 and then the address x at which 8 is stored

h. Valid

Dynamically allocating memory to x and y. Then 2 values are entered from stdin. If the vaules entered are equal, assign the address pointed by y to z, and x to y. Also, check if address location pointed by x and y are same, then print the values at the address pointed by x and y which would be same.

i. Valid

Both x and z point to the same memory location whch have value 20. So a will have 400

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote