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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. i want some lesson for dynamic declaration

i want some lesson for dynamic declaration

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
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.
  • C Offline
    C Offline
    CHEICKNA TRAORE
    wrote on last edited by
    #1

    Hi, I have an array like this : char sArray[4][5]; I want to declare this array with new or malloc like this : char** sArray=NULL; sArray = new char[20]; or sArray = (char*)malloc(20); Can anybody help me to write correct declaration Thanks in advance

    C 1 Reply Last reply
    0
    • C CHEICKNA TRAORE

      Hi, I have an array like this : char sArray[4][5]; I want to declare this array with new or malloc like this : char** sArray=NULL; sArray = new char[20]; or sArray = (char*)malloc(20); Can anybody help me to write correct declaration Thanks in advance

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      there is no simple way to do it in C++. you will have to do something like this:

      // alloc an array of arrays
      int ** array = new int* [sizex];
      for (int i = 0; i < sizex; ++i)
      array[i] = new int[sizez];

      -c


      "Half of the harm that is done in this world is due to people who want to feel important." -- TS Elliot

      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