Question 5 What does the following program do? Question 5 options: It prints 1 2
ID: 2079934 • Letter: Q
Question
Question 5
What does the following program do?
Question 5 options:
It prints 1 2 3 4.
The program incurs a segmentation fault when run.
It does not compile. You cannot copy arrays like that.
It does not compile. You cannot print an entire array like that.
question 6
Arrays are just pointers in disguise.
Question 6 options:
Question 7
Declaring too large an array in a function may cause a stack overflow when the function is called.
Question 7 options:
Question 8
What does the following program do?
Question 8 options:
It crashes because main can only return 0.
It returns 3.
It returns 4.
It does not compile.
Question 9
What does the following program do?
Question 9 options:
It does not compile.
It prints: 1 1 1 1 1
Prints: 1 2 3 4 5.
It crashes because it causes a segmentation fault.
Question 10
What does the following program do?
Question 10 options:
It crashes because p != a+n accesses an address that isout of bounds.
It doesn't compile. You cannot assign an array to a pointer because they are of different types.
It prints nonsense because %d is for integers, while p is a pointer.
It prints: 0 1 2 3 4
AIt prints 1 2 3 4.
BThe program incurs a segmentation fault when run.
CIt does not compile. You cannot copy arrays like that.
DIt does not compile. You cannot print an entire array like that.
Explanation / Answer
5. We will get a compilation error stating that "incompatible types when assigning to type 'int[4]' from type 'int *'"
6. True
Arrays in C++ are actually just pointers in disguise! When an array is passed to a function, C++ passes a pointer to the rst element of the array. This way, the array does not have to be copied. Because the address is used, the function can change data outside the scope of the function.
7. True.
In this case allocation should be done in heap memory not stack.
8. It does not compile.
error: assigning to an array from an initializer list
a = {1,2,3,4};
9.Prints: 1 2 3 4 5.
10.It prints: 0 1 2 3 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.