RicardasSim

NULL array

Apr 1st, 2020
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define ARR_SIZE_1 10
  5. #define ARR_SIZE_2 10
  6. #define ARR_SIZE_3 10
  7.  
  8. int arr1[ARR_SIZE_1];
  9.  
  10. int main()
  11. {
  12.  
  13.     for ( int i = 0; i < ARR_SIZE_1; ++i )
  14.     {
  15.         printf("%d", arr1[i]);
  16.     }
  17.  
  18.     printf("\n");
  19.  
  20.     int arr2[ARR_SIZE_2]={0};
  21.  
  22.     for ( int i = 0; i < ARR_SIZE_2; ++i )
  23.     {
  24.         printf("%d", arr2[i]);
  25.     }
  26.  
  27.     printf("\n");
  28.  
  29.     int *arr3[ARR_SIZE_3]={NULL};
  30.  
  31.     for ( int i = 0; i < ARR_SIZE_3; ++i )
  32.     {
  33.         printf("%s", arr3[i] ? "y" : "n" );
  34.     }
  35.  
  36.     printf("\n");
  37.  
  38.     int var1 = 1;
  39.  
  40.     arr3[2] = &var1;
  41.  
  42.     for ( int i = 0; i < ARR_SIZE_3; ++i )
  43.     {
  44.         printf("%p ", (void*) arr3[i] );
  45.     }
  46.  
  47.     printf("\n");
  48.  
  49.     return 0;
  50. }
  51.  
  52. /*
  53. output:
  54.  
  55. 0000000000
  56. 0000000000
  57. nnnnnnnnnn
  58. (nil) (nil) 0x7fff2af2312c (nil) (nil) (nil) (nil) (nil) (nil) (nil)
  59.  
  60. */
Advertisement
Add Comment
Please, Sign In to add comment