Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. 2 dim numbers..

2 dim numbers..

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _8086
    wrote on last edited by
    #1

    int* pInt = new int[2*3]; 6 elements So you can access it like pInt[0],1,2,.. now i want to acess it as a 2dim. for example, 0 1 2 3 4 5 Or 0 1 2 3 4 5 i have declared a pointer like int (*pintPtr)[2][3]; Now how do I assign this to pInt? something like , pintPtr=((int*)[2][3])&pInt;? This do not work. Please help.

    ---------------------------- 286? WOWW!:-O

    M 1 Reply Last reply
    0
    • _ _8086

      int* pInt = new int[2*3]; 6 elements So you can access it like pInt[0],1,2,.. now i want to acess it as a 2dim. for example, 0 1 2 3 4 5 Or 0 1 2 3 4 5 i have declared a pointer like int (*pintPtr)[2][3]; Now how do I assign this to pInt? something like , pintPtr=((int*)[2][3])&pInt;? This do not work. Please help.

      ---------------------------- 286? WOWW!:-O

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      void main()
      {
      int (*p)[3] = new int[2][3];
      int i, j;
      for(i = 0; i < 2; i++) {
      for(j = 0; j < 3; j++) {
      p[i][j] = i +j;
      }
      printf("\n");
      }
      int (*pX)[3] = p;
      for(i = 0; i < 2; i++) {
      for(j = 0; j < 3; j++) {
      printf("%d ", pX[i][j]);
      }
      printf("\n");
      }
      printf("\n");
      for(i = 0; i < 2; i++, pX++) {
      for(j = 0; j < 3; j++) {
      printf("%d ", (*pX)[j]);
      }
      printf("\n");
      }
      delete [] p;
      }


      Maxwell Chen

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups