Week 07 Tutorial Questions
How is everyone going with the assignment? Are you enjoying it?
Where can you go to get help?
Write a function that takes in a 2D array of int
s and multiplies every
value in the array by a given int
.
It will have this prototype:
void scalar_multiply(int rows, int columns, int matrix[rows][columns], int scalar);
What is a pointer? How can you declare and initialise a pointer?
What will happen when each of the following statements is executed (in order)?
int n = 42;
int *p, *q;
p = &n;
*p = 5;
*q = 17;
q = p;
*q = 8;
Filling out the follwing table may be helpful:
Address | int n = 42; |
int *p; int *q; |
p = &n; |
*p = 5; |
*q = 17; |
q = p; |
*q = 8; |
---|---|---|---|---|---|---|---|
0xFF80 |
|||||||
0xFF84 |
|||||||
0xFF88 |
|||||||
0xFF8C |
|||||||
0xFF90 |
What does the char *word
input mean? What's the
relationship between an array and a pointer?
What is a struct? What are the differences between structs and arrays?
This C code:
int x;
int a[6];
x = 10;
a[3 * 2] = 2 * 3 * 7;
printf("%d\n", x);
mysteriously printed 42
. How could this happen when x
is clearly assigned only the value 10
?
How does the output change if we create a another int
after the array?
How can you easily detect such errors before they have mysterious effects?