RicardasSim

array address, sizeof

Jul 6th, 2019
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.     char str1[10]={0};
  10.    
  11.     printf("Address:\n\n");
  12.    
  13.     printf("str1: %p\n", (void*) str1);
  14.     printf("&str1: %p\n", (void*) &str1);
  15.     printf("&str1[0]: %p\n", (void*) &str1[0]);
  16.     printf("&str1[1]: %p\n", (void*) &str1[1]);
  17.    
  18.     printf("\nsizeof:\n\n");
  19.    
  20.     printf("str1: %zu\n", sizeof str1);
  21.     printf("&str1: %zu\n", sizeof &str1);
  22.     printf("&str1[0]: %zu\n", sizeof &str1[0]);
  23.     printf("&str1[1]: %zu\n", sizeof &str1[1]);
  24.     printf("*str1: %zu\n", sizeof *str1);
  25.     printf("str1[0]: %zu\n", sizeof str1[0]);
  26.    
  27.     return 0;
  28. }
  29.  
  30. /*
  31. output:
  32.  
  33. Address:
  34.  
  35. str1: 0x7fff497215be
  36. &str1: 0x7fff497215be
  37. &str1[0]: 0x7fff497215be
  38. &str1[1]: 0x7fff497215bf
  39.  
  40. sizeof:
  41.  
  42. str1: 10
  43. &str1: 8
  44. &str1[0]: 8
  45. &str1[1]: 8
  46. *str1: 1
  47. str1[0]: 1
  48.  
  49. */
Advertisement
Add Comment
Please, Sign In to add comment