Week 07 Tutorial Questions

  1. Well done everyone for such a great effort in the first assignment.

    Take a moment to think about how you found the assignment, and what you learned in the process of working on it.

    If you could go back in time to the very start of the assignment, and give one piece of advice to your past self, what would you say?

    You tutor will talk about how you will get feedback from the marking of assignment 1.

  2. So far in this course we have learnt about two data types - int and double. What about a char variable? What is the size of this variable, and what possible values can it have? What do these values mean?

  3. So far in this course we have only used scanf and printf to scan input and print output in our programs.

    How do we use getchar and putchar? How does getchar signal to us that it has reached the end of the input?

    Why does getchar return an int instead of a char?

    How do we use fgets? How does fgets signal to us that it has reached the end of the input?

    When fgets scans in a line of text, will it include a '\n' at the end of the line? Is this always the case?

  4. What does the following function do?

    int secret_function(char *word) {
        int i = 0;
        int result = 0;
        while (word[i] != '\0') {
            if(word[i] >= 'a' && word[i] <= 'z') {
                result++;
            }
            i++;
        }
        return result;
    }
    
  5. Can you explain the stopping case in the while loop? Why does it work and what is the significance of the '\0'?

  6. What does the char *word input mean? What's the relationship between an array and a pointer?

  7. What is a pointer? How do pointers relate to other variables?

  8. What is a struct? What are the differences between structs and arrays?