Week 04 Tutorial Questions
-
The tutorial will start with a code review.
Your tutor has asked a lab pair to present their week 3 work.
Discuss the good, the bad and the ugly aspects of their code.
Please be gentle in any criticism - we are all learning!
- What is Minesweeper? Have you played the game before?
- How does the Assignment version of Minesweeper differ from the game?
- How does Minesweeper store a minefield and how can you access a single square?
-
Draw a 2D grid on a piece of paper or the whiteboard and draw where mines would
be for the following coordinates:
6 7
4 4
3 6
Can you think of how a computer would check for how many mines there are in a particular row or column of the minefield?
-
Scanf is a function that can have a result. This result will be the number
of values it has read and assigned to variables.
For example:
int result = scanf("%d", &variable);
The variable result will have the value 1 if one integer was read from the user. We call input from the user "standard input".
Discuss how we could create a loop that would continually read values in from standard input until the user inputs anything other than a number (or the input ends). This question will be continued in one of the Lab exercises this week.
- What is an array?
-
Write a function called firstPlusThird that sums the first and third element of an array called
numbers
and returns the answer. -
If an array is declared as
int numbers[20];
and your program assigns a value to each element in the array, what is the problem with the statementx = numbers[20];
? -
How would you declare a variable squares to be an array of
integers with 15 elements?
Write a C code function to store, in each element of this array, the square of the index of that element, e.g., squares[5] would contain the value 25.
Note that arrays are very special in that, if they are given as the input to a function, the function will have access to the array and can change it. We'll cover why this is and the difference between that and variables later!