Please help me with these short questions? Suppose that p is an int* variable. W
ID: 3712916 • Letter: P
Question
Please help me with these short questions?
Suppose that p is an int* variable. Write several lines of code that will make p point to an array of 100 integers, place the numbers 0 through 99 into the array components, and return the array to the heap.
What happens if you call new but the heap is out of memory?
Draw a picture of memory after these statements:
int i = 42;
int k = 80;
int* p1;
int* p2;
p1 = &i;
p2 = &k;
Suppose that we execute the statements from the previous question, and then we execute these statements:
*p1 = *p2;
Draw a picture of memory after this additional statement.
Draw a picture of memory after these statements:
int i = 42;
int k = 80;
int* p1;
int* p2;
p1 = &i;
p2 = &k;
p1 = p2;
Here is a function prototype:
void exam (const double data[]);
Write two or three sentences to tell me all the information that you know about the parameter.
Multiple Choice
Consider the following statements:
int *p;
int i;
int k;
i = 42;
k = i;
p = &i;
After these statements, which of the following statements will change the value of i to 75?
A. k = 75;
B. *k = 75;
C. p = 75;
D. *p = 75;
E. Two or more of the answers will change i to 75.
Consider the following statements:
int i = 42;
int j = 80;
int *p1;
int *p2;
p1 = &i;
p2 = &j;
*p1 = *p2;
cout << i << j << endl;
What numbers are printed by the output statement?
A. 42 and then another 42
B. 42 and then 80
C. 80 and then 42
D. 80 and then another 80
What is printed by these statements?
int i = 1;
int k = 2;
int *p1;
int *p2;
p1 = &i;
p2 = &k;
p1 = p2;
*p1 = 3;
*p2 = 4;
cout << i;
A. 1
B. 2
C. 3
D. 4
What is printed by these statements?
int i = 1;
int k = 2;
int* p1;
int* p2;
p1 = &i;
p2 = &k;
p1 = p2;
*p1 = 3;
*p2 = 4;
cout << k;
A. 1
B. 2
C. 3
D. 4
What is printed by these statements?
int i = 1;
int k = 2;
int* p1;
int* p2;
p1 = &i;
p2 = &k;
*p1 = *p2;
*p1 = 3;
*p2 = 4;
cout << i;
A. 1
B. 2
C. 3
D. 4
When allocating an array of objects, what constructor is used to initialize all of the objects in the array?
A. The automatic copy constructor.
B. The constructor specified at the declaration.
C. The default constructor.
D. None of the above.
In which location do dynamic variables reside?
A. The code segment.
B. The data segment.
C. The heap.
D. The run-time stack.
When should a pointer parameter p be a reference parameter?
A. When the function changes p, and you want the change to affect the actual pointer argument.
B. When the function changes p, and you do NOT want the change to affect the actual pointer argument.
C. When the function changes *p, and you want the change to affect the the object that is pointed at.
D. When the function changes *p, and you do NOT want the change to affect the the object that is pointed at.
E. When the pointer points to a large object.
Suppose you have the following function prototype and variable declaration:
void goop(int z[ ]);
int x[10];
Which is the correct way to call the goop function with x as the argument:
A. goop(x);
B. goop(x[ ]);
C. goop(x[10]);
D. goop(&x);
E. goop(&x[ ]);
Suppose that the goop function from the previous question changes the value of z[1]. Does this change affect the value of the actual argument?
A. Yes
B. No
Here is a function declaration:
void goo(int* x)
{
*x = 1;
}
Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you print *a after the function call goo(a)?
A. 0
B. 1
C. address of a
D. address of x
E. None of the above
Explanation / Answer
According to chegg guidelines i have to solve first four bits but i solve all bits(Multiple choice questions).
1.
Consider the following statements:
int *p;
int i;
int k;
i = 42;
k = i;
p = &i;
After these statements, which of the following statements will change the value of i to 75
Option D correct
2.
Consider the following statements:
int i = 42;
int j = 80;
int *p1;
int *p2;
p1 = &i;
p2 = &j;
*p1 = *p2;
cout << i << j << endl;
Option D correct
3.
When allocating an array of objects, what constructor is used to initialize all of the objects in the array the default constructor.
Option c correct
4.
dynamic variables reside run-time stack.
Option D correct
5.
A pointer parameter p be a reference parameter when the function changes *p, and you want the change to affect the the object that is pointed at.
Option C correct
6.
Which is the correct way to call the goop function with x as the argument:
Option A correct
7.
Suppose that the goop function from the previous question changes the value of z[1]. Does this change affect the value of the actual argument
Option A correct
8.
Here is a function declaration:
void goo(int* x)
{
*x = 1;
}
Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you print *a after the function call goo(a)
Option B correct.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.