Advertisement
dllbridge

Untitled

Jul 3rd, 2024
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3.  
  4. /////////////////////////////////
  5. struct   Big
  6. {
  7.     int length;
  8.     int  width;
  9.     int   nMax;
  10. };
  11.  
  12.  
  13. void foo(Big *);
  14.  
  15. ////////////////////////////////////////////
  16. int main()
  17. {
  18.     Big  b;
  19.    
  20.     b.length = 12;
  21.     b. width =  2;    
  22.     b.  nMax =  5;
  23.    
  24.     foo(&b);  
  25. }
  26.  
  27. /////////////////////////////////////////////
  28. void foo(Big *p)
  29. {
  30.     printf(" - - - - - \n");
  31.     printf("address b.length = %d\n",   &p->length);
  32.     printf("address b. width = %d\n",   &p-> width);
  33.     printf("address b.  nMax = %d\n",   &p->  nMax);   
  34.     printf(" p = %d\n", p);
  35.    
  36.     char *pn = (char*)p;
  37.    
  38.     pn = pn + 4;
  39.    
  40.     printf(" pn = %d\n", pn);  
  41.    
  42.     // Распечатать адреса всех полей структуры без упоминания их имён
  43. }
  44.  
  45.  
  46.  
  47. /*
  48. #include<stdio.h>
  49.  
  50. /////////////////////////////////
  51. struct   Big
  52. {
  53.     int length;
  54.     int  width;
  55. };
  56.  
  57.  
  58. void foo(Big *);
  59.  
  60. ////////////////////////////////////////////
  61. int main()
  62. {
  63.     Big a, b;
  64.    
  65.     a.length = 12;
  66.     b.length =  5;
  67.     b. width =  2;    
  68.     printf("        a.length = %d\n",   a.length);
  69.     printf("address a.length = %d\n", & a.length);
  70.     printf("address a. width = %d\n", & a. width);
  71.    
  72.     foo(&b);  
  73. }
  74.  
  75. /////////////////////////////////////////////
  76. void foo(Big *p)
  77. {
  78.     printf(" - - - - - \n");
  79.     printf("address b.length = %d\n",   &p->length);
  80.     printf("address b. width = %d\n",   &p-> width);
  81.     printf(" p = %d\n", p);
  82.    
  83.     char *pn = (char*)p;
  84.    
  85.     pn = pn + 4;
  86.    
  87.     printf(" pn = %d\n", pn);  
  88. }
  89.  
  90.  
  91.  
  92. */
  93.  
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement