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. Array's again

Array's again

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformance
13 Posts 7 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.
  • H Offline
    H Offline
    hackC
    wrote on last edited by
    #1

    What I was wondering is when i put. const size_t array = 3; int ca[array] = {0,1,2}; cout << ca << endl; The program prints 0x75dfc0 (or something like that, I'm just guessing) that output tells me nothing. Is it the memory address or what. it all seems a little confusing.

    T K M 3 Replies Last reply
    0
    • H hackC

      What I was wondering is when i put. const size_t array = 3; int ca[array] = {0,1,2}; cout << ca << endl; The program prints 0x75dfc0 (or something like that, I'm just guessing) that output tells me nothing. Is it the memory address or what. it all seems a little confusing.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      #hackC++ wrote:

      const size_t array = 3; int ca[array];

      1. you cannot do this. you must use either macros or dynamic memory allocation.

      #hackC++ wrote:

      cout << ca << endl;

      this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

      H M R 3 Replies Last reply
      0
      • H hackC

        What I was wondering is when i put. const size_t array = 3; int ca[array] = {0,1,2}; cout << ca << endl; The program prints 0x75dfc0 (or something like that, I'm just guessing) that output tells me nothing. Is it the memory address or what. it all seems a little confusing.

        K Offline
        K Offline
        Kharfax
        wrote on last edited by
        #3

        mate you need an ebook about C or a tutorial about c arrays Search in google and read it

        T H 2 Replies Last reply
        0
        • T toxcct

          #hackC++ wrote:

          const size_t array = 3; int ca[array];

          1. you cannot do this. you must use either macros or dynamic memory allocation.

          #hackC++ wrote:

          cout << ca << endl;

          this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

          H Offline
          H Offline
          hackC
          wrote on last edited by
          #4

          Would it be easier to use vectors in most cases?

          T 1 Reply Last reply
          0
          • T toxcct

            #hackC++ wrote:

            const size_t array = 3; int ca[array];

            1. you cannot do this. you must use either macros or dynamic memory allocation.

            #hackC++ wrote:

            cout << ca << endl;

            this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

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

            #hackC++ wrote:

            const size_t array = 3; int ca[array];

            v2.0 wrote:

            1. you cannot do this. you must use either macros or dynamic memory allocation.

            Yes we can, because it is const. At least my GCC compiles this code.


            Maxwell Chen

            1 Reply Last reply
            0
            • H hackC

              Would it be easier to use vectors in most cases?

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              #hackC++ wrote:

              Would it be easier to use vectors in most cases?

              depends what you need to do with it. if you need an array which size need to change often, then yes, vector is certainly a good choice. please explain what you want to do with that array if you want me to advise you better.

              1 Reply Last reply
              0
              • T toxcct

                #hackC++ wrote:

                const size_t array = 3; int ca[array];

                1. you cannot do this. you must use either macros or dynamic memory allocation.

                #hackC++ wrote:

                cout << ca << endl;

                this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

                R Offline
                R Offline
                Roland Pibinger
                wrote on last edited by
                #7

                v2.0 wrote:

                #hackC++ wrote: const size_t array = 3; int ca[array]; 1. you cannot do this.

                You can in C++ (not in C).

                v2.0 wrote:

                #hackC++ wrote: cout << ca << endl; this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

                'iterate' means a for-loop ;)

                T 1 Reply Last reply
                0
                • R Roland Pibinger

                  v2.0 wrote:

                  #hackC++ wrote: const size_t array = 3; int ca[array]; 1. you cannot do this.

                  You can in C++ (not in C).

                  v2.0 wrote:

                  #hackC++ wrote: cout << ca << endl; this prints ca which is a pointer to the first int which compounds the array, so what you get is actually the address at which the array has been allocated... if you want to print each elements in the array, iterate over it.

                  'iterate' means a for-loop ;)

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  Roland Pibinger wrote:

                  'iterate' means a for-loop

                  iterate means "go thru each element" by the way you like (for, do or while loop can do the job)...

                  1 Reply Last reply
                  0
                  • K Kharfax

                    mate you need an ebook about C or a tutorial about c arrays Search in google and read it

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    i quite agree with that ;)

                    1 Reply Last reply
                    0
                    • K Kharfax

                      mate you need an ebook about C or a tutorial about c arrays Search in google and read it

                      H Offline
                      H Offline
                      hackC
                      wrote on last edited by
                      #10

                      Well i'm currently reading C++ Primer 4th Edition by Stanley Lippman. just got done reading about vectors and went into arrays which is confusing me to say the least. The complier I'm using is Bloodshed Dev C++. By the way, whats the best software for C++. i'm guessing Visual Basic C++ 2003 but i could be wrong. -- modified at 14:00 Tuesday 25th April, 2006

                      T D 2 Replies Last reply
                      0
                      • H hackC

                        Well i'm currently reading C++ Primer 4th Edition by Stanley Lippman. just got done reading about vectors and went into arrays which is confusing me to say the least. The complier I'm using is Bloodshed Dev C++. By the way, whats the best software for C++. i'm guessing Visual Basic C++ 2003 but i could be wrong. -- modified at 14:00 Tuesday 25th April, 2006

                        T Offline
                        T Offline
                        toxcct
                        wrote on last edited by
                        #11

                        #hackC++ wrote:

                        Well i'm currently reading C++ Primer 4th Edition by Stanley Lippman.

                        when you get stronger C++ programmer, i advise you to read The C++ Language by Bjarne Stroustrup (the C++ Creator).

                        #hackC++ wrote:

                        By the way, whats the best software for C++.

                        i'm not sure about what you're saying here, but if you ask for an IDE, then i think most people here will tell you that Microsoft Visual C++ 2003/2005 worth it (because Codeproject is dedicated to microsoft technologies). you can get Visual Studio 2005 Express edition for free on MS web site.

                        1 Reply Last reply
                        0
                        • H hackC

                          What I was wondering is when i put. const size_t array = 3; int ca[array] = {0,1,2}; cout << ca << endl; The program prints 0x75dfc0 (or something like that, I'm just guessing) that output tells me nothing. Is it the memory address or what. it all seems a little confusing.

                          M Offline
                          M Offline
                          Michael Dunn
                          wrote on last edited by
                          #12

                          You can't output a whole array like that. What's happening is an implicit conversion from int[] to int*, and you're seeing the value of that pointer (the address of array[0])

                          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                          1 Reply Last reply
                          0
                          • H hackC

                            Well i'm currently reading C++ Primer 4th Edition by Stanley Lippman. just got done reading about vectors and went into arrays which is confusing me to say the least. The complier I'm using is Bloodshed Dev C++. By the way, whats the best software for C++. i'm guessing Visual Basic C++ 2003 but i could be wrong. -- modified at 14:00 Tuesday 25th April, 2006

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #13

                            #hackC++ wrote:

                            just got done reading about vectors and went into arrays which is confusing me to say the least.

                            Technically, a vector is a one-dimensional array. Things get confusing because C++ has a vector type.

                            #hackC++ wrote:

                            By the way, whats the best software for C++.

                            It depends on what you use to measure with. One person might like it for features A, B, and C, while the next person hates those features but likes X, Y, and Z instead.


                            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                            "We will be known forever by the tracks we leave." - Native American Proverb

                            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