LearnFrenzy
Sign in Take a free test

Typedef · Exercise 4 of 4

Typedef typedef Programs

  • 8 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Programs where typedef makes the design clearer – custom types, callbacks and small data structures. Write each one yourself first, then open the solution; every solution was compiled and run, and the output shown is the real output.

Question 1 Medium

Create a Fraction type with add and multiply functions that always return the fraction in lowest terms, with the sign in the numerator.

Question page & discussion
Question 2 Hard

Implement a fixed-capacity circular queue type with enqueue and dequeue that report "full" and "empty".

Question page & discussion
Question 3 Medium

Write map() that applies any int → int function to each element, using a typedef for the callback type.

Question page & discussion
Question 4 Medium

Define a Date type and compute the day of the year (with leap years) and the number of days between two dates in the same year.

Question page & discussion
Question 5 Medium

Wrap a 2×2 matrix in a typedef'd struct so it can be returned by value, then multiply two matrices and compute a determinant.

Question page & discussion
Question 6 Medium

Map event names to handler functions in a table and dispatch events by name, reporting unknown events.

Question page & discussion
Question 7 Medium

Using typedef uint8_t Byte;, compute an 8-bit XOR checksum and an 8-bit additive checksum of a message.

Question page & discussion
Question 8 Medium

Using typedef struct node Node;, build a list by appending values, print it with its length, and free it.

Question page & discussion
All exercises doneBack to TypedefRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links