Monday, 26 August 2013

Chapter 8 Solutions Problem [L][a]

Question-How will you initialize a three-dimensional array
threed[3][2][3]? How will you refer the first and last element
in this array?

Solution-
Extremely trivial question. let's look up the solution.
 I am using Pointer notation for printing first and last elements.

#include <stdio.h>
#include <stdlib.h>

int main()
{
int arr[3][2][3]={{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}},{{13,14,15},{16,17,18}}};
printf("First element=%d\nLast element=%d\n",***arr,*(*(*(arr+2)+1)+2));
return 0;
}
 

2 comments:

  1. Earthmoving Spare Parts
    This is my Good luck that I found your post which is according to my search and topic, I think you are a great blogger, thanks for helping me out from my problem..

    ReplyDelete
    Replies
    1. Well, Thanks ..If you are not being sarcastic ...

      Delete