top of page

COMP1005

For solutions, purchase a LIVE CHAT plan or contact us

​

Question 1 (Total: 28 marks)
(a) What are the values of and after the following code has
been executed and and are both set to before the code
is executed?
i=++j;
j=i++;
Answers:
(4 marks)
(b) What are the values of the variables , , , , , and after
the following code has been executed?
int i = 2, j = 3, k;
float x = 0.5, y = 2.5, z;
k=i / j + 1;
z = x + i / j
if (++i > 2 && j++ <= 3)
k += 5;
x /= y - x;
y = y == 1;
Answers:
(12 marks)
(c) What are the values of the variables , , and
after the following code fragment is executed?
Answers:
(12 marks)

Question 2 (Total: 18 marks)
For each one of the variables , , , , , and , list the storage
class, scope and lifetime of the variable.
Answers:
storage class scope lifetime
(18 marks)

Question 3 (Total: 30 marks)
The C program on the following page was written to provide a
function which calculates and returns the first
prime numbers (in this case the first 10 prime num-
bers). To test the function, the programmer has printed out the
numbers returned by the function. However, the program does
not work - there are TEN mistakes in the source code which
prevent the program from working correctly. Find the ten mis-
takes, and for each mistake identify the line number containing
the mistake.
Answers:
Mistake 1 line number:
Mistake 2 line number:
Mistake 3 line number:
Mistake 4 line number:
Mistake 5 line number:
Mistake 6 line number:
Mistake 7 line number:
Mistake 8 line number:
Mistake 9 line number:
Mistake 10 line number:
(30 marks)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

Question 4 (Total: 24 marks)
Given the following variable declarations:
And that the array is stored starting from memory address
and that integers are 4 bytes, what are the values returned by
the following expressions? Memory addresses should be given in
hexadecimal.
Answers:
Expression Value
(24 marks)

For solutions, purchase a LIVE CHAT plan or contact us

​

​

Limited time offer:

Follow us on Instagram and tag 10 friends for a $50 voucher! No minimum purchase required.

bottom of page