fork(2) download
  1. #include <stdio.h>
  2.  
  3. struct address {
  4. char street[100];
  5. char city[20];
  6. char state[2];
  7. char zip[10];
  8. };
  9. struct date {
  10. int month;
  11. int day;
  12. int year;
  13. };
  14. struct user {
  15. char login[20];
  16. char fullname[100];
  17. char password[30];
  18. struct address physical_address;
  19. struct date birthday;
  20. int user_type;
  21. union {
  22. struct {
  23. double salary;
  24. char *clearance;
  25. } admin;
  26. struct {
  27. struct date donationdate[2];
  28. double amount[2];
  29. } donor;
  30. struct {
  31. double wage;
  32. struct date datehired;
  33. } worker;
  34. } userinfo;
  35. } __attribute__((packed));
  36.  
  37. struct user users[200];
  38.  
  39. int main (int argc, char *argv[]) {
  40. printf("char: %u, int: %u, double %u, pointer: %u\n",
  41. sizeof(char), sizeof(int), sizeof(double), sizeof(void *));
  42. printf("%u\n", (char *)&users[10] - (char *)users
  43. + 1000);
  44. printf("%u\n", (char *)&users[15].physical_address.street - (char *)users
  45. + 1000);
  46. printf("%u\n", (char *)&users[20].birthday.year - (char *)users
  47. + 1000);
  48. printf("%u\n", (char *)&users[20].userinfo.donor.amount[1] - (char *)users
  49. + 1000);
  50. }
  51.  
Success #stdin #stdout 0s 2312KB
stdin
Standard input is empty
stdout
char: 1, int: 4, double 8, pointer: 4
4380
6220
8050
8090