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. How to NULL arrays?

How to NULL arrays?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
6 Posts 4 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
    CreepingFeature
    wrote on last edited by
    #1

    Following my first dumb question, I #include number[2]. Sorry about that! Being a newb is a bitch!!! :laugh: How do you NULL arrays? Is it ok to: int numbers[10] = { 1, 23, 50, 2, NULL}; Or do I have to: int numbers[10] = {NULL}; and then assign values using a second statment! Apriciate the help!

    L D 2 Replies Last reply
    0
    • C CreepingFeature

      Following my first dumb question, I #include number[2]. Sorry about that! Being a newb is a bitch!!! :laugh: How do you NULL arrays? Is it ok to: int numbers[10] = { 1, 23, 50, 2, NULL}; Or do I have to: int numbers[10] = {NULL}; and then assign values using a second statment! Apriciate the help!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      why do you wan't to NULL them? There's no need to

      1 Reply Last reply
      0
      • C CreepingFeature

        Following my first dumb question, I #include number[2]. Sorry about that! Being a newb is a bitch!!! :laugh: How do you NULL arrays? Is it ok to: int numbers[10] = { 1, 23, 50, 2, NULL}; Or do I have to: int numbers[10] = {NULL}; and then assign values using a second statment! Apriciate the help!

        D Offline
        D Offline
        digwizfox
        wrote on last edited by
        #3

        There is another thread that started just this morning, asking a very similar question about how to initialize arrays with zero values. See "Arrays!" by CreepingFeature which was posted at 8:58 this morning. There are many replies that will answer your questions on array initialization. Best Regards, Shawn

        C 1 Reply Last reply
        0
        • D digwizfox

          There is another thread that started just this morning, asking a very similar question about how to initialize arrays with zero values. See "Arrays!" by CreepingFeature which was posted at 8:58 this morning. There are many replies that will answer your questions on array initialization. Best Regards, Shawn

          C Offline
          C Offline
          CreepingFeature
          wrote on last edited by
          #4

          That was my thread!:omg:

          D 1 Reply Last reply
          0
          • C CreepingFeature

            That was my thread!:omg:

            D Offline
            D Offline
            digwizfox
            wrote on last edited by
            #5

            Ya don't say. Well I'm confused then. NULL stands for the number zero. If you really want to use NULL you have to write a for loop, I'm sorry to say. But that is rather pointless if it is zero anyway. Just follow the advice on the other thread. Shawn

            A 1 Reply Last reply
            0
            • D digwizfox

              Ya don't say. Well I'm confused then. NULL stands for the number zero. If you really want to use NULL you have to write a for loop, I'm sorry to say. But that is rather pointless if it is zero anyway. Just follow the advice on the other thread. Shawn

              A Offline
              A Offline
              Antti Keskinen
              wrote on last edited by
              #6

              As arrays of data are placed sequentically in memory (at least on unmanaged/non .Net programs), then you can use ZeroMemory to set the entire array area to zero. Alternatively, you can use ZeroMemory in conjuction with array indexes to clear certain sections. A few examples:

              // Create an array
              int nArray[20];

              // Clear the first three "slots"
              ZeroMemory( &nArray[0], sizeof(int) * 3 );

              // Clear slots 10-15
              ZeroMemory( &nArray[10], sizeof(int) * 5);

              // Clear the last slot
              ZeroMemory( &nArray[19], sizeof(int) );

              Hope these will help you. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

              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