In: Computer Science
(a) In C++, write down the main method including a for loop. The body of the for loop includes the followings :
i. an if condition
ii. an array (of any type & of any size)
iii. a structure variable (with at least two variables of any type)
(b) Show the corresponding code contents in memory for the main method and draw the stack contents while the main method starts execution and reaches at the line prior to return from your main method of Problem 3(a).
(c) Create a symbol table structure (dynamic scoping) at the line before returning from your main method of Problem 3(a).
(a) Code:
#include <iostream>
using namespace std;
struct Abc // initialise
structure
{
int x1,y1;
};
int main()
{
int arr[2]; //an array (of
int type & of 2 size)
struct Abc y={6,8}; //a
structure variable (with at least two variables of any
type)
int x=0;
for(int i=1; i<=10;
i++){
if(i==y.x1){ // if
condition
arr[x]=i;
x++;
}
if(i==y.y1){
arr[x]=i;
x++;
}
}
for(int i=0; i<2;
i++){
cout<<arr[i]<<"
";
}
}
Output:
Answering only (a) since this is a complete question in itself, please add other parts as separate questions