Skip to the task
Layout
Back to classic view

You are looking at lesson 2. Your place is still lesson 6, task 1: Arrays.

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 Create this file. Every line is new: see the green bar.
#include <stdio.h>
int main(void) {
const int current_year = 2026;
Note 1: const: the program can't change this value any more.
int study_year = 1;
char group = 'A';
Note 2: A char is one character in single quotes.
int birth_year = 2007;
double average = 8.75;
int age = current_year - birth_year;
Note 3: The starting value is worked out from other variables.
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);
Note 4: A double with 2 digits after the dot, rounded.
printf("In memory: int %zu B, double %zu B, char %zu B\n", sizeof study_year, sizeof average,
Note 5: sizeof: how many bytes the variable takes; format %zu.
sizeof group);
return 0;
}