How The Address or Value Access from 3D array using pointers?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnagJohari
    New Member
    • May 2010
    • 96

    How The Address or Value Access from 3D array using pointers?

    Code:
    main( )
    {
      int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
    printf("%u %u %u %d \n",a,*a,**a,***a);
    printf("%u %u %u %d \n",a+1,*a+1,**a+1,***a+1);
     	 }

    If the location of an array start from 100.

    can you please explain all this by giving the demonstration of how the location is saved from one to other & how the location & the value is access please explain in detail.
    Thank you
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You might want to start by running the code and seeing if you can explain it.

    As a tip it may (or may not) help if all the values in the array have different values so you can easily differentiate them.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You might also read this article: http://bytes.com/topic/c/insights/77...rrays-revealed.

      There is a lot of info here about how arrays actually work.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        You are using %u (unsigned int) to print [some] pointer values. Are you sure int is wide enough on your platform?

        I suggest changing your array declaration from int to unsigned long and then using conversion specifier "%lu". Unsigned long isn't guaranteed to be wide enough to hold a pointer value either, but from a practical point of view it is good enough.

        Comment

        Working...