Skip to the task
Layout
Back to classic view

You are looking at lesson 2. Your place is still lesson 10, task 1: struct.

RUNTask 5 of 23 · step 3: The student cardRun p02_card
Run p02_card in practice/02/

File → Reload CMake Project, pick p02_card and ▶. Then change birth_year to your own year and run it again.

Checklist

  • Every task is one commit with a clear message.

Numbered notes in the code explain the important lines.

Details & hint
$ .\build\debug\practice\02\p02_card.exe
Year of study: 1
Group: PI25A
Age: 19 years
Average: 8.75
In memory: int 4 B, double 8 B, char 1 B

You should see: Five lines. The average with two digits after the dot, and int, double and char take 4, 8 and 1 bytes.

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;
}
opened for this task
$ .\build\debug\practice\02\p02_card.exe
Year of study: 1
Group: PI25A
Age: 19 years
Average: 8.75
In memory: int 4 B, double 8 B, char 1 B