Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Types.

CREATETask 4 of 23 · step 3: The student cardCreate the student card
Create the student card in practice/02/

Declare the variables with suitable types, work out the age and print everything with printf.

Checklist

  • Every task is one commit with a clear message.

Numbered notes in the code explain the important lines.

Details & hint
  • const int current_year is the current year: it doesn't change in the program.
  • Every variable gets a starting value as soon as it is declared.
  • int age = current_year - birth_year;: a starting value can be an expression.
  • Formats: %d for int, %c for char, %.2f for a double with 2 digits, %zu for sizeof.

Stuck? The last printf is long, so its arguments continue on the next line. That is also how Ctrl+Alt+L lays it out (topic 4).

practice 02 main.c Code Diff +20
A · NEW FILE git diff: every line is new (+20).
--- /dev/null
+++ b/practice/02/main.c
@@ -0,0 +1,20 @@
+ #include <stdio.h>
+
+ int main(void) {
+ const int current_year = 2026;
+ int study_year = 1;
+ char group = 'A';
+
+ int birth_year = 2007;
+ double average = 8.75;
+
+ int age = current_year - birth_year;
+
+ printf("Year of study: %d\n", study_year);
+ printf("Group: PI25%c\n", group);
+ printf("Age: %d years\n", age);
+ printf("Average: %.2f\n", average);
+ printf("In memory: int %zu B, double %zu B, char %zu B\n", sizeof study_year, sizeof average,
+ sizeof group);
+ return 0;
+ }