LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Exercise 4 of 4

Declarations and Initializations Declaration Programs

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

Programs that rely on the right declarations and initializers. 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

Declare a student record with designated initializers (leaving one member out) and print it with the average of the marks.

Question page & discussion
Question 2 Easy

Using an initialised array of month lengths, print the number of days in each quarter of a non-leap year.

Question page & discussion
Question 3 Easy

Print the remainder of 7.5 / 2 and 3.14 / 2.1, and round 2.5 and −2.5 with round(), floor() and ceil().

Question page & discussion
Question 4 Medium

Keep default settings in a const struct, then replace a copy with new values using a compound literal.

Question page & discussion
Question 5 Medium

Declare an enum with explicit values for some HTTP status codes and print a message for each, including an unknown code.

Question page & discussion
Question 6 Medium

Show the difference between a writable char array and a read-only literal by changing a copy of each.

Question page & discussion
Question 7 Easy

Declare a 4 × 4 array initialised to zero, fill cells 1–3 with a times table, and show that untouched cells are still zero.

Question page & discussion
Question 8 Hard

Using C23 constexpr for the size and nullptr for free slots, declare a table of bookings with designated initializers and list them.

Question page & discussion
All exercises doneBack to Declarations and InitializationsRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links