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. Managed C++/CLI
  4. C++ Question

C++ Question

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++data-structures
5 Posts 5 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.
  • D Offline
    D Offline
    DiscoBall 13
    wrote on last edited by
    #1

    Given the declaration. int *a; The statement. a = new int [50]; Dynamically allowcates an array of 50 components of the type? int, int*, pointer, address?

    K T L 3 Replies Last reply
    0
    • D DiscoBall 13

      Given the declaration. int *a; The statement. a = new int [50]; Dynamically allowcates an array of 50 components of the type? int, int*, pointer, address?

      K Offline
      K Offline
      koothkeeper
      wrote on last edited by
      #2

      You get a pointer to an array of 50 unique integers.

      1 Reply Last reply
      0
      • D DiscoBall 13

        Given the declaration. int *a; The statement. a = new int [50]; Dynamically allowcates an array of 50 components of the type? int, int*, pointer, address?

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

        int* a; declares a as a pointer to an int. a = new int[50] allocates an array of 50 int, and then returns the address of the array in memory into a. then, you can code a[1] to access the 2nd cell on the array. if you wanted an array of pointers to int, you should write this :

        int* a;
        a = new int*[50];

        cheers,


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        A 1 Reply Last reply
        0
        • T toxcct

          int* a; declares a as a pointer to an int. a = new int[50] allocates an array of 50 int, and then returns the address of the array in memory into a. then, you can code a[1] to access the 2nd cell on the array. if you wanted an array of pointers to int, you should write this :

          int* a;
          a = new int*[50];

          cheers,


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Not quite. That would be: // 50 new pointers to integers. int **a = new (int *)[50]; // Parentheses might not be necessary. int *b = a[0]; // Assign one element of the array to an int pointer. int c = 0; // New integer on the stack b = &c; // Assign a value to the pointer. a[0] = &c; // Same effect as the above line. *b = 5; // Assign a value to the integer pointed to by b. *(a[0]) = 5; // Same effect as the above line. (Note: I wrote this code in the input box and didn't compile it to double-check if it works, so if I got something wrong please correct me.) Like the other posters said, the code "int *a = new int[50]" allocates an array of 50 integers on the heap and assigns a to the address of the beginning of that array.

          1 Reply Last reply
          0
          • D DiscoBall 13

            Given the declaration. int *a; The statement. a = new int [50]; Dynamically allowcates an array of 50 components of the type? int, int*, pointer, address?

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

            Thank You very much I wish I would of found this site Last year because I Graduated today from Farmingdale suny I thank all comrades of this site Thank You:laugh::laugh:

            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