You are on page 1of 4

Group One Lab Work

List of Group Members:

Osman Yahaya
Akoje Sydney
Yaaka Vug Godfred

HND Computer Science II

Data Structures and Algorithm
QUESTION 1
#include <iostream>
using namespace std;
int main ()
{
int* count;
cout << "the address of the varible is <<&count <<endl;
return 0;
}
QUESTION 2
#include <iostream>
using namespace std;
int main ()
{
double* dPtr;
return 0;
}

QUESTION 3
1 The asterick is used together with forward slash as a comment
2 is also used to declare a pointer
3 Is used as multiplication operator

QUESTION 4
50 60 70
500 300 140

QUESTION 5
QUESTION 6
The pointer ptr will now hold the address of 12010.
QUESTION 7
A) Is valid
B) Is valid
C) Is valid
D) Is valid
E) Is valid
QUESTION 8
A) Is valid
B) Is invalid because of the comma.
C) Is valid
D) Is invalid because of the comma
E) Is valid
QUESTION 9.
A. True
B. False
C. True
D. False
10. proper way to call the following function in order to negate the
void makeNegative(int *val)
{
if(*val > 0)
*val = -(*val);
}
int num = 7;
makeNegative(&num);
cout << num<< endl;

QUESTION 12.
int * ip = new int;
// ...
delete ip;

// dynamically created int

// deletes the space that ip points to

QUESTION 13.
int * ip;
ip = new int[500];
for(int i = 0; i < 500; i++)
*(ip + i) = 255;
delete [] ip;
QUESTION 14.
a.

#include <iostream>
using namespace std;
int main ()
{
int *ptr = NULL;
cout << "The value of ptr is " << ptr ;
return 0;
}

B. Function That Correctly Returns A Pointer.

Function:
int* test (int* a, int* b) {
int* c = new int[5];
for (int i = 0; i < 5; i++) c[i] = a[i]+b[i];
return c;
}
Call Function:
int m1[5] = {1, 2, 3, 4, 5};
int m2[5] = {6, 7, 8, 9, 10};
int* m3 = test(m1, m2);
for (int i = 0; i < 5; i++) cout<<m3[i]<<endl;
cout<<endl;
delete[] m3;
C.FUNCTION THAT INCORRECTLY RETURNS A POINTER
struct a {

int value;
a::a(int val) {
value = val;
}
a* clone() {
a* ret = new a(value);
return ret;
}
};