LearnFrenzy
Sign in Take a free test

Complicated Declarations · Exercise 4 of 4

Complicated Declarations Complicated Declaration Programs

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

Programs that put function pointers, pointers to arrays and complex declarations to work. 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 Easy

Store four arithmetic functions in an array of function pointers and run a list of menu choices against it, rejecting invalid choices.

Question page & discussion
Question 2 Medium

Write map() and filter() that take a function pointer, and use them to square the numbers of an array and keep only the multiples of 3.

Question page & discussion
Question 3 Hard

Model a traffic light where each state is a function that returns the next state. A function cannot return its own pointer type directly, so wrap it in a struct.

Question page & discussion
Question 4 Medium

Write functions taking int (*m)[3] parameters to transpose a 3 × 3 matrix in place and print it.

Question page & discussion
Question 5 Hard

Write order() that returns a qsort comparator for "asc", "desc" or "abs" ordering, and sort the same data three ways.

Question page & discussion
Question 6 Medium

Keep a small registry of handlers (event name + function pointer taking a const char *). Register three, then fire events, including one with no handler.

Question page & discussion
Question 7 Medium

Build a jagged array (rows of different lengths) as an array of pointers to int plus an array of lengths, and print each row with its sum.

Question page & discussion
Question 8 Easy

Write apply_n(f, n, x) that applies the function f to x n times, and use it with doubling and with the Collatz step.

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

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links