← Back to 25T3

Tutorial 0: Revision

MTRN2500 25T3



MTRN2500 has two possible prerequisite courses: COMP1531 and COMP2521. COMP1511 is also a relevant course that is not technically a prerequisite; note that it is a prerequisite of COMP1531/COMP2521 and is a requirement of the mechatronics (MTRNAH) engineering major.

Revision questions specifically related to C (taught in COMP1511) are also included — however, most C-specific concepts will be revisited in the course (albeit at a faster pace and in context of learning C++).

Programming Fundamentals

  1. Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Sample output:

1 2 Fizz 4 Buzz ...
  1. Complete the following function which returns the sum of all the elements squared in a given array. The function should have the following signature (choose the language you are most comfortable with):
// C int sumSquares(int arr[], int length);
// JavaScript/TypeScript function sumSquares(arr: number[]): number;
# Python def sumSquares(arr: List[int]) -> int:
// C++ int sumSquares(std::vector<int> arr);
  1. Write a function that returns the third largest element in an array/list of integers. You may assume that the array/list has at least 3 elements. The function should have the following signature (choose the language you are most comfortable with):
// C int thirdLargest(int arr[], int length);
// JavaScript/TypeScript function thirdLargest(arr: number[]): number;
# Python def thirdLargest(arr: List[int]) -> int:
// C++ int thirdLargest(std::vector<int> arr);

C

  1. What steps are required in order to run a C program.
  1. Which of these variables have valid names?
int V3RX; int var; int 3var; int _3; int __var;
  1. What is a pointer? What is a memory address?
  1. Complete the following function:
void swap(int *a, int *b) { // TODO: implement a function that swaps the values at addresses a and b }
  1. What is the difference between stack and heap memory? How would you allocate memory on the stack or heap?
  1. What is an array? How would you declare an array on the stack and on the heap?
  1. What is a struct?
  1. What is a linked list?
  1. What is ASCII?
  1. Identify code which has bad style. Explain how this could be improved.
#include <stdio.h> #define CONST 10 int main(){ int VAR=3 *CONST; printf("%d\n", VAR); VAR = 4; printf("%d\n", VAR); }
  1. Usually array indexing would be done like arr[i] . Explain why this code works as well?
int arr[4] = {42, 52, 62, 72}; for (int i = 0; i < 4; i++) { printf("%d\n", i[arr]); }
  1. What is the difference between a compiler warning and error?

Git Commands

  1. Create a git repository.
  1. Clone an existing git repository.
  1. Show the status of the repository.
  1. Stage changes for commit.
  1. Commit changes.
  1. Checkout to a branch
  1. Merge a branch into the current branch.
  1. Push changes to a remote repository (e.g. GitHub or GitLab)
  1. Amend the last commit message.
  1. Check the changes that have been made but not yet committed.
  1. Show the commit history.
  1. Reset to a previous commit.
  1. Reset the git history to a previous commit but keep the current code.

go to answers