Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

want first and second element

//Character arrays and pointers
#include<stdio.h>
#include<string.h>

int main()
{
	int C[3][2][2] = { { { 2, 5 }, {7,9} },
						{ {3,48}, {6,1} },
						{{27,8}, {11,13} } };
	printf("%d %d %d %d\n", C, *C, C[0], &C[0][0]);
	int row;
	int col;
	int z;
	for (row = 0; row<5; row++){
		for (col = 0; col < 5; col++){
			for (z = 0; z < 5; z++){
				printf("[%d][%d][%d]=%d\n", row, col,z, *(C[row][col] + 1));
			}//end z
		}//end col
	}//end row
}

Open in new window


I want to iterate through all the values of
int C[3][2][2]

I guessed row,col, z???
and my output only shows second element in each {}
how do I display both

this is not a homework question.
0
rgb192
Asked:
rgb192
1 Solution
 
ozoCommented:
//Character arrays and pointers
#include<stdio.h>
#include<string.h>

int main()
{
      int C[3][2][2] = { { { 2, 5 }, {7,9} },
                                    { {3,48}, {6,1} },
                                    {{27,8}, {11,13} } };
      printf("%p %p %p %p\n", C, *C, C[0], &C[0][0]);
      int row;
      int col;
      int z;
      for (row = 0; row<3; row++){
            for (col = 0; col < 2; col++){
                  for (z = 0; z < 2; z++){
                        printf("[%d][%d][%d]=%d\n", row, col,z, C[row][col][z]);
//  /*or equivalently*/ printf("[%d][%d][%d]=%d\n", row, col,z, *(C[row][col]+z));
                  }//end z
            }//end col
      }//end row
}
0
 
rgb192Author Commented:
Thanks I forgot the 'z'
C[row][col][z]
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now