Week 02 Tutorial Questions
- What are the types of variables that we've seen so far and what do they represent?
- What is the difference between a variable and a constant?
- What is the difference between declaring variable and using #define?
-
What is the syntax of C
if
statements? What is the role ofif
statements in programs? -
A leap year is a year that has 366 days instead of 365. There is a leap year every year
divisible by four except for years which are both divisible by 100 and not divisible by 400.
For more detail information of leap years see: Leap Year
Draw a simple flow chart showing the branches of possibilities to decide if a year is a Leap Year.
For some humourous information about flow charts see: Flow Charts (xkcd).
Can you then write some simple code using if/else statements in C that decides if a year is a Leap Year? (hint: modulus is a useful way to decide whether a number is divisible by another) This code question will be continued in this week's lab, so try to remember or keep a copy/photo of the diagram and code you've written.
-
The value of CÂ arithmetic operations depends on the types of the operand.
If the types of the operands differ, CÂ automatically converts the types as appropriate.
Determine the value of each expression and sub-expression:
- 1 / 2 * 500
- 1 / 2.0 * 500
- (17 / 5) * 5 + (17 % 5)
- (12 - 17) % 6 - 4
-
The and (&&) and or (||) operators can be used to combine multiple statments into one (such as the statements created in the leap year activity).
Write either a true or false statement about this dog and share with the class.
Are your classmates' statments true or false?
(Source: Jeffree Star Cosmetics, 2012)For example:
- The dog is pink || blue
- The dog is pink && blue
-
Write a program
rectangle_area.c
that reads in 2 integers which are the side-length of a rectangle, and then prints the area of the rectangle.For example:
./rectangle_area Please enter rectangle length: 3 Please enter rectangle width: 5 Area = 15 ./rectangle_area Please enter rectangle length: 42 Please enter rectangle width: 42 Area = 1764
- What is a bit?
- What is a byte?
- How many distinct values can be represented with a single byte?
- How would we represent integers using 4 bits? Is there some kind of scheme we could use to reliably store integer information using bits?
- What is a file?
- What is a directory?