1. 1) Write a statement to declarean array alpha and initialize its components t
ID: 3608896 • Letter: 1
Question
1. 1) Write a statement to declarean array alpha and initialize its components to 10,20, and 30.
2. 2) After execution of the codefragment
Int arr[5];
Int I;
For (I = 0; i<5; i++)
{
Arr[i] =i+2;
If (i>=3)
Arr[i-1]=arr[i] +3;
}
What is contained in arr[1]?
3. 3) What is the output of thefollowing program fragment ?
Int alpha[5] = {100, 200, 300, 400, 500};
Int I;
For (i=4; i>0; i--)
Cout << alpha [i] << ‘ ‘;
4. 4) Given a 5000-elemnt,one-dimensional array beta, write a code fragment that could beused to print out the values of beta[0], beta[2], beta[4], and soforth.
(all variables are of type int.)
5. 5) True or false? dynamic datacan be deallocated during program execution, but static dataremains until the program terminates.
A) True.
B) False.
6. 6) True or false? If the newoperator fails in its attempt to allocate memory, the computersystem aborts the program and prints an error message.
A) True.
B) False.
Explanation / Answer
1) Write a statementto declare an array alpha and initialize its components to 10,20,and 30.
2. 2) After execution of the code fragment
intarr[5];
int i;
For (i= 0; i<5; i++)
{
Arr[i] =i+2;
If (i>=3)
Arr[i-1]=arr[i] +3;
}
What is contained in arr[1]?
arr[1]=3
3. 3) What is the output of the following program fragment ?
Int alpha[5] = {100, 200, 300, 400, 500};
Int I;
For (i=4; i>0; i--)
Cout << alpha [i] << ‘ ‘;
500 400 300200
4. 4) Given a 5000-elemnt, one-dimensional array beta, write acode fragment that could be used to print out the values ofbeta[0], beta[2], beta[4], and so forth.
(all variables are of type int.)
for(i=0;i<5000;i=i+2)
cout<<beta[i]<<""; //these will all print on 1 line
5. 5) True or false? dynamic data can be deallocated duringprogram execution, but static data remains until the programterminates.
A) True.
B) False.
6. 6) True or false? If the new operator fails in its attemptto allocate memory, the computer system aborts the program andprints an error message.
A) True.
B) False.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.