RicardasSim

sizeof, variable, pointer

Dec 1st, 2020
842
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Linux 64bit, -std=c99 -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. char c;
  7. char *p_c;
  8.  
  9. int n;
  10. int *p_n;
  11.  
  12. long l;
  13. long *p_l;
  14.  
  15. float f;
  16. float *p_f;
  17.  
  18. double d;
  19. double *p_d;
  20.  
  21. int main()
  22. {
  23.     printf( "sizeof c %zu\n", sizeof c );
  24.     printf( "sizeof &c %zu\n", sizeof &c );
  25.     printf( "sizeof p_c %zu\n", sizeof p_c );
  26.     printf( "sizeof *p_c %zu\n\n", sizeof *p_c );
  27.  
  28.     printf( "sizeof n %zu\n", sizeof n );
  29.     printf( "sizeof &n %zu\n", sizeof &n );
  30.     printf( "sizeof p_n %zu\n", sizeof p_n );
  31.     printf( "sizeof *p_n %zu\n\n", sizeof *p_n );
  32.  
  33.     printf( "sizeof l %zu\n", sizeof l );
  34.     printf( "sizeof &l %zu\n", sizeof &l );
  35.     printf( "sizeof p_l %zu\n", sizeof p_l );
  36.     printf( "sizeof *p_l %zu\n\n", sizeof *p_l );
  37.  
  38.     printf( "sizeof f %zu\n", sizeof f );
  39.     printf( "sizeof &f %zu\n", sizeof &f );
  40.     printf( "sizeof p_f %zu\n", sizeof p_f );
  41.     printf( "sizeof *p_f %zu\n\n", sizeof *p_f );
  42.  
  43.     printf( "sizeof d %zu\n", sizeof d );
  44.     printf( "sizeof &d %zu\n", sizeof &d );
  45.     printf( "sizeof p_d %zu\n", sizeof p_d );
  46.     printf( "sizeof *p_d %zu\n\n", sizeof *p_d );
  47.  
  48.     return 0;
  49. }
  50.  
  51. /*
  52. output:
  53.  
  54. sizeof c 1
  55. sizeof &c 8
  56. sizeof p_c 8
  57. sizeof *p_c 1
  58.  
  59. sizeof n 4
  60. sizeof &n 8
  61. sizeof p_n 8
  62. sizeof *p_n 4
  63.  
  64. sizeof l 8
  65. sizeof &l 8
  66. sizeof p_l 8
  67. sizeof *p_l 8
  68.  
  69. sizeof f 4
  70. sizeof &f 8
  71. sizeof p_f 8
  72. sizeof *p_f 4
  73.  
  74. sizeof d 8
  75. sizeof &d 8
  76. sizeof p_d 8
  77. sizeof *p_d 8
  78.  
  79. */
  80.  
RAW Paste Data