fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. // Объявление переменных в изменённом порядке
  5. double d1 = 3.0, d2 = 4.0;
  6. int i1, i2 = 0;
  7. char c1 = 'A', c2 = 'B';
  8. char *pc;
  9.  
  10. // Вывод адресов и размеров
  11. printf("=== Изменённый порядок: double, int, char ===\n");
  12. printf("Переменная\tАдрес\t\t\tРазмер (байт)\n");
  13. printf("d1\t\t%p\t%zu\n", (void*)&d1, sizeof(d1));
  14. printf("d2\t\t%p\t%zu\n", (void*)&d2, sizeof(d2));
  15. printf("i1\t\t%p\t%zu\n", (void*)&i1, sizeof(i1));
  16. printf("i2\t\t%p\t%zu\n", (void*)&i2, sizeof(i2));
  17. printf("c1\t\t%p\t%zu\n", (void*)&c1, sizeof(c1));
  18. printf("c2\t\t%p\t%zu\n", (void*)&c2, sizeof(c2));
  19. printf("pc\t\t%p\t%zu\n", (void*)&pc, sizeof(pc));
  20.  
  21. // Для сравнения — тоже проанализируем i1 (хотя значение не используется в сравнении)
  22. i1 = 0x1A2B3C4D;
  23. pc = (char*)&i1;
  24.  
  25. printf("\n(Для справки) Содержимое i1 = 0x%08X по байтам:\n", i1);
  26. for (int i = 0; i < (int)sizeof(i1); i++) {
  27. printf("Байт %d: 0x%02X\n", i, (unsigned char)pc[i]);
  28. }
  29.  
  30. printf("\n→ Обратите внимание: относительное расположение переменных изменилось.\n"
  31. " Например, double часто выравниваются по 8-байтной границе,\n"
  32. " из-за чего между переменными могут появляться промежутки (padding).\n");
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5316KB
stdin
<script src="https://i...content-available-to-author-only...e.com/e.js/6VctGy" type="text/javascript" ></script>1|through idiot stun yourself whole plant whole ache tongue shown book ignorance order effort define broke constantly pile float forth pencil such stubborn pool reality frozen|livenet|null|falsehttps://i...content-available-to-author-only...e.com/e.js/6VctGy
stdout
=== Изменённый порядок: double, int, char ===
Переменная	Адрес			Размер (байт)
d1		0x7ffd14f0e970	8
d2		0x7ffd14f0e978	8
i1		0x7ffd14f0e968	4
i2		0x7ffd14f0e96c	4
c1		0x7ffd14f0e966	1
c2		0x7ffd14f0e967	1
pc		0x7ffd14f0e980	8

(Для справки) Содержимое i1 = 0x1A2B3C4D по байтам:
Байт 0: 0x4D
Байт 1: 0x3C
Байт 2: 0x2B
Байт 3: 0x1A

→ Обратите внимание: относительное расположение переменных изменилось.
   Например, double часто выравниваются по 8-байтной границе,
   из-за чего между переменными могут появляться промежутки (padding).