CSE 701 Practice Exam 1: Chapters 1-3
McMaster University, Fall 2026

Table of contents

Notes about the practice exam ^

This practice exam is in the same format, length, and difficulty level as the real exam, and covers the same material. You are prepared for the real exam if you can solve all the questions in this practice exam on your own, with no help from anyone else, human or AI.

Tips for effective AI usage: If you just give the exam questions to an LLM and copy its answers, you will never learn how to solve questions yourself, and you will not be prepared for the actual exam. However, once you have solved the practice exam on your own, you can ask an LLM to check your answers and give you feedback, or even generate additional practice exams for you in a similar format.

Instructions ^

You have 1 hour to solve the exam. There are 8 questions in total, and the points sum up to 100.

The only allowed material during the exam is the course lecture notes, in printed form. You are not allowed to write anything on the printed notes or modify them in any way before or after printing, but you can use a highlighter.

Computers, phones, tablets, smart watches, smart glasses, and other digital devices cannot be used during the exam. Any students found using a digital device of any kind during the exam will be charged with academic dishonesty.

In addition to ensuring correct C syntax, you must also make sure to closely follow all the programming guidelines and best practices we learned in class, as outlined in the lecture notes - especially those inside the colored warning boxes.

Question 1 (10 points) ^

What does it mean for a language to be "higher-level" than another language?

Question 2 (12 points) ^

The following C program has errors. Find all the errors and explain why each of them is an error. Rewrite the program without these errors, so that it works correctly and prints out the expected output.

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main(void)
{
    int64_t x;
    int64_t y = 6;
    printf("5 * 6 = %s", x * y)
    x = 5;
}

Question 3 (12 points) ^

The following C program has errors. Find all the errors and explain why each of them is an error. Rewrite the program without these errors, so that it works correctly and prints out the expected output.

#include <inttypes>
#include <stdint>
#include <stdio>

int main(void)
{
    const uint64_t x = -100;
    x++;
    printf("-100 + 1 = " PRIu64, x);
}

Question 4 (12 points) ^

The following program is not portable, meaning it may produce different outputs on different operating systems. Explain why that is. Fix it so that it is portable and produces the same output on all operating systems.

#include <stdio.h>

int main(void)
{
    const long x = 3000000000;
    printf("%ld", x + 1);
}

Question 5 (12 points) ^

What will be the output of the following program?

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main(void)
{
    int64_t a = 1;
    int64_t b = (a == 2) ? 3 : 4;
    int64_t c;
    if (b = 3)
        c = 5;
    else
        c = 6;
    int64_t d = 7;
    switch (c)
    {
    case 5:
        d = 8;
    case 6:
        d = 9;
    }
    printf("%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, a, b, c, d);
}

Question 6 (12 points) ^

What will be the output of the following program?

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int64_t x = 256;
int64_t y = 512;

void swap(void)
{
    int64_t temp = x;
    x = y;
    y = temp;
}

int main(void)
{
    int64_t x = 1024;
    int64_t y = 2048;
    swap();
    printf("x = %" PRId64 ", y = %" PRId64, x, y);
}

Question 7 (15 points) ^

Write a function int_power() that takes two positive integers a and b and returns the first integer to the power of the second integer. For example, int_power(4, 3) will return 64. Your function must NOT use the built-in pow() function or any other math function from math.h or tgmath.h.

Note that you do not need to write a full program, just one function. However, the function must be complete and correct, such that if you enter it as-is into a program in VS Code, it will compile and run successfully without any errors or warnings (with all the warning flags recommended in this course enabled) and produce the expected output for any reasonable input. Make sure that the function follows all the guidelines below!

Question 8 (15 points) ^

Write a program that finds and prints the largest and smallest elements of the array {6.4, 3.0, -23.3, 5349.2, -311.1, 10.5}.

This must be a complete and correct program, with all the header files, main() function, and so on, such that if you enter it as-is into VS Code, it will compile and run successfully without any errors or warnings (with all the warning flags recommended in this course enabled) and produce the expected output. Make sure that the program follows all the guidelines below!

Note for the practice test ^

The real test will be very similar to the practice test. You will be asked similar questions. It is highly recommended to solve the practice exam on paper, so you can get used to writing code on paper. However, once you are done you should copy your code to a computer and make sure it compiles and all code produces the expected output. Enable all warning flags recommended in this course, and the clang-tidy and cppcheck linters, and ensure that there are no warnings or errors in your code.

Guidelines ^

Here are some important C programming guidelines to follow when solving this practice exam and the real exam:

  • Always use const for any variable or function argument that should not be modified.
  • Always use portable integer types with the appropriate signedness and bit width for the task at hand, and size_t for sizes and array indices.
  • Always use floating-point types with the appropriate range and precision for the task at hand. (In practice, this usually means using double unless you have a very good reason to use something else.)
  • Never use uninitialized variables, access array elements out of range, or dereference null or invalid pointers.
  • Beware of integer or floating-point overflows, and floating-point rounding errors.
  • Beware of implicit type conversions that may lead to unexpected results.
  • Avoid global variables.
  • Variables should always occupy the smallest possible scope. For example, a for loop variable should be declared within the for statement itself, not beforehand.
  • Never shadow variables.
  • Always anticipate and handle all possible errors, such as when opening files or processing user input.

Please note that these are general guidelines; not all of them apply to this practice exam or to the real exam. This list will not be included in the real exam, but all these guidelines can be found in the lecture notes, which you will have access to during the exam.

© 2026 Barak Shoshany