Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

41 строка
1.3 KiB
C++

#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdint>
using namespace std;
struct Student {
char name[17];
uint16_t enrollment_year;
float gpa;
uint8_t gender : 1; // 0 = female, 1 = male
uint8_t courses_completed;
Student* group_leader;
};
void print_memory_info(const Student& student) {
cout << "Name address: " << &student.name << ", size: " << sizeof(student.name) << endl;
cout << "Year address: " << &student.enrollment_year << ", size: " << sizeof(student.enrollment_year) << endl;
cout << "GPA address: " << &student.gpa << ", size: " << sizeof(student.gpa) << endl;
cout << "Gender address: " << &student.gender << ", size: 1 bit" << endl;
cout << "Courses address: " << &student.courses_completed << ", size: " << sizeof(student.courses_completed) << endl;
cout << "Leader address: " << &student.group_leader << ", size: " << sizeof(student.group_leader) << endl;
}
int main() {
Student students[3] = {
{"Alice", 2021, 3.8, 0, 5, nullptr},
{"Bob", 2021, 3.5, 1, 4, nullptr},
{"Charlie", 2020, 3.9, 1, 6, &students[0]}
};
for (size_t i = 0; i < 3; ++i) {
cout << "Student " << i + 1 << " memory info:" << endl;
print_memory_info(students[i]);
cout << endl;
}
return 0;
}