Answer a: Till program ends as it is defined as static
Answer b: with in the fun
Answer c:stack as it is local
Answer d:untill the funciton ends
Answer e:heap as we are creating memory dynamically
Note : Please comment below if you have concerns. I am here to
help you
If you like my answer please rate and help me it is very Imp for
me
5. (10%) Consider the following C code segment: int fun (int a, int b) { static...
Please show all your work
PROBLEM 5 (10 points) Consider the following code in syntax and assume stack memory allocation for nested scope is used. In the following questions, write None if none apply #include <stdlib.h> intess a; // memory a int main 0 { intes b; // memory B + inte c; // memory s c - (int) malloc(sizeof (int)); // memory 1 (int**) malloc(sizeof(int:)); // memory 2 b b - &c; a - (int***) malloc(sizeof (int**)); // memory...
1. What are the contents of the numbers array at the end of this code? int numbers[] = { 35, 57, 78, 66, 41, 12 }; int *ptrA = numbers + 3; int x = 15; *ptrA = x++; 2. Which of the following expressions is the correct way of dynamically allocating memory for a struct named MyStruct? MyStruct *m = malloc( sizeof( MyStruct ) ); MyStruct m = (MyStruct) malloc( MyStruct ); MyStruct *m = (MyStruct *) malloc( MyStruct...
1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int start, int end, int *results) { int length = end - start; results = malloc(sizeof(int) * length); for (int i=start; i<end; i++) { *results = i; results++; } } void printArray(int *arr, int length) { for (int i=0; i<length; i++) { printf("%d ", arr[i]); } } int main() { int *x; int s = 2; int e = 11; range(s, e, x); printArray(x, e...
Question 5: A) Consider: int i=1; int fun(int x) { for(int i=0; i<4; i++) { x += i; return x; What value is returned by a function call fun(1)? B In C, static variables can only be initialized by literals, not functions. For example, this is allowed: static int x = 5; But this is not allowed: static int x = compute_initial(); Why would this be the case? A Because you can never initialize a variable using a function, even...
Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...
please help me with this question
(in C programming language and Unix)
computer system book 3 edition
int *fun (int *x)f int value *xtt return &value; int main) int pl; int **p2; int a; char str [5] printf ("Enter a number:") scanf("%d", a) ; printf ("Enter a line:") gets (str); p1-malloc(sizeof (int)) *pl-p2; p2-malloc(sizeof (int)); pl-fun (a); n-0; for (pl-stripl<-str+5;pl++) if (isdigit (pl)) at+; return 0; Construct a table that shows for each line of code, what may be the...
In the following C program, indicate the variable type (global, local, or static local), the lifetime (when the program is run or when the function is called), and the memory allocation (from stack or from heap) for each variable (x, y, z, and w) defined in the program. int w; void fun (int x) { int y; static float z; ... } void main() { fun(w); }
What is the likely results of running the following code fragment? Why? int *ptr = (int *) 0xfeedbeef ; *ptr = 0 ; Suppose a class uses a dynamically-allocated integer array, pointed to by an int* variable named data. The current capacity of the array is stored in the integer variable capacity. The following code fragment is meant to dyamically resize the array, doubling its capacity. What is the major memory error and how would you detect it? int *tmp...
Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...
Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30; i-i+3) if(i%) values.add(i); return values: What is returned after the method call nums()? a. [12] b. [13] c. [14] d. [15] e. [16] O Which of the following represents the final output of the code segment below? int k: int[]A; A new int[3]: fork-0; k<A.length;k++) A[k]-A.length-k; forſk-0; k<A.length-1; k++) A[k+1]-A[k) for(int i-0;i<A.length;i++) System.out.print(A[i]+" "); a. 222 O b. 333 c. 444 d. 555 O...