4. Suppose the following code is written to define variables called my dub and y
ID: 3753391 • Letter: 4
Question
4. Suppose the following code is written to define variables called my dub and your_dub to store arrays of doubles. What statement below is true? double your dub [1-114.3, 10.8. 5.0) double my dub- malloc(sizeof (double) *3) a. the array contents of my dub and your dub are stored on the heap b. the array contents of my dub and your dub are stored on the stack c. the array contents of my dub is stored on the stack; the array contents of your dub is stored on the heap the array contents of my_dub is stored on the heap: the array contents of your dub is stored on the stack d. 5. Consider the following code snippet. int my-arr[] = {1, 2, 3, 4, 5); nt your arr(1 -smy_arr [21, smy_arr11, smy_arr (4) What is the value of (your_arr (21)? a. b. 2 C. 5 d. 6 e. Error: array out of bounds 6. Suppose the following code is written in main, all necessary libraries are included, the code compiles and is executed: int arl)-110,15,20,25,0) int pari int out-0 while (out-*pt+) printf ("id ",out) What is printed? a. 10 15 20 25 b. 10 15 20 25 . 10 15 20 25 d. Segmentation error e. None of the aboveExplanation / Answer
Answer 4:
(d) is true as dynamically allocated memory is stored on the heap while statically allocated memory is stored on to the stack. In this case my_dub is dynamically allocated memory for 3 double variables whereas your_dub is allocated memory statically for 3 double variables.
Answer 5:
(c) 5 is the value of *(your_arr[2])
as *(your_arr[2]) means *( *(your_arr + 2)) which means *( &my_arr[4]) which finally means my_arr[4] which is 5
Answer 6:
(c) 10 15 20 25
Because when p will point to element 0 of ar, the while loop will be terminated because *p will be 0.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.