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

For each variable and parameter (totally 10 of them) in the C++ program shown be

ID: 664310 • Letter: F

Question

For each variable and parameter (totally 10 of them) in the C++ program shown below (you could answer a. b. together):

a. Categorize the variable/parameter lifetime as static, stack-dynamic, or heap-dynamic.
b. Clearly describe the scope of the variable/parameter.
c. Clearly describe the environment (in terms of which variables and parameters are accessible) at each numbered comment line

#include iostream.h> const int size = 64; typedef int IntArray[ size]. int GetArrSize (IntArray arr, int maxsize // comment line l void main (int argc, charargv[]) IntArray arr int i = 0; int max size = size; // comment line 2 if (argc 2) exit(l).: while ((1max size) &6 (argv[1][1] != '10')) // comment line 3 arr [1] argv[1][1]; = if (1 = maxsize) i = max size - 1; argv [1] = ''; cout GetArrSize (arr, maxsize) endl ; int GetArrSize(IntArr ay arr, int maxsize) // comment line 4 int size = 0; static int cal Is = 0; call3+H: while ((arr[size ] != '') returnfsize): // comment line 5 && (size

Explanation / Answer

arr,maxsize and i are stack dynamic

size and intarray are heap variables

calls is static variable

heap variables can be accessed by any subroutine and function.

stack based can be called by local scope and are de-allocated once the program execution is finishes

static variables retain thier value even after execution of the program scope finishes.

comment line 1 is heap dynamic

comment line 2 and 3 is stack dynamic