/
Nik135
/
Homeworks
Обзор
Документация
Войти
/
Nik135
/
Homeworks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
b1.c
60 строк
1 KB
Nik135
дз
21 фев 2026, 21:34
Верифицирован
21 фев 2026, 21:34
bca67d5
Код
Авторство
О чём код?
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list { void *address; size_t size; char comment[64]; struct list *next; } list; size_t totalMemoryUsage(list *head) { size_t total = 0; for (list *cur = head; cur != NULL; cur = cur->next) total += cur->size; return total; } int main() { list *head = NULL; list *node; node = malloc(sizeof(list)); node->address = (void*)140525067852320; node->size = 10; strcpy(node->comment, "Block 1"); node->next = head; head = node; node = malloc(sizeof(list)); node->address = (void*)140525067852350; node->size = 30; strcpy(node->comment, "Block 2"); node->next = head; head = node; node = malloc(sizeof(list)); node->address = (void*)140525067852900; node->size = 100; strcpy(node->comment, "Block 3"); node->next = head; head = node; size_t total = totalMemoryUsage(head); printf("Total memory usage: %zu\n", total); while (head) { node = head; head = head->next; free(node); } return 0; }