Question: Practice Test 1 1 . What unfortunate misinterpretation can occur with the following declaration? int * intpPr 1 , intPtr 2 ; Your Answer: 2

Practice Test1
1. What unfortunate misinterpretation can occur with the following declaration?
int* intpPr1, intPtr2;
Your Answer:
2. What do the following statements print?
int values[]={2,3,5};
cout <<*values +2<<"";
cout <<*(values +2)<< endl;
Your Answer:
3. Trace the following code that modifies the array. The write the modified array in the
space provided.
1 #include
2 using namespace std;
3
4 int main()
5{
6 int values ={1,2,3,5,7,9};
7 int* p = values;
8 int* q = values +3;
9 while (p < q)
10{
11 int temp =*p;
12*p =*q;
13*q = temp;
14 p++;
15 q--;
16}
17}
To trace the code, first fill in the
initial values of p and q as indices.
After that the loop starts.
p q temp *p *q
Answer: values[]=
4. Find errors in memory allocation in the following segments:
code Explain the errors if any
int p ;
p =5 ;
delete p ;
int p = new int [10] ;
p =5
delete p ;
5.The following segment has errors. Locate as many as you can.
int* getNum()
{
int wholeNum;
cout << "Enter a number: ";
cin >> wholeNum;
return &wholeNum;
}
6. Consider the following code:
string s1, s2("Hello");
cout << "Enter a line of input: ";
cin >> s1;
if (s1== s2)
{
cout << "Equal
";
}
else
{
cout << "Not equal
";
}
If the dialogue begins as follows, what will be the next line of output?
Enter a line of input:
Hello friend
Your answer:
7. Assume input is a char array holding a C-string. Write code that counts the number
of elements in the array that contain an alphabetic character.
8. Write a function that accepts an int array and the arrays size as arguments. The
function should create a new array that is twice the size of the argument array. The
function should copy the contents of the argument array to the new array and initialize
the unused elements of the second array with 0. The function should return a pointer to
the new array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!